Skip to content

Commit

Permalink
treewide: Refactor to per-project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzleutgeb committed Apr 15, 2024
1 parent c0a2671 commit 186e149
Show file tree
Hide file tree
Showing 46 changed files with 225 additions and 111 deletions.
27 changes: 0 additions & 27 deletions configs/all-configurations.nix

This file was deleted.

File renamed without changes.
88 changes: 64 additions & 24 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
rust-overlay,
dream2nix,
...
}: let
} @ inputs: let
inherit
(builtins)
readDir
mapAttrs
attrValues
isAttrs
concatStringsSep
;

inherit
Expand All @@ -45,26 +46,53 @@
nixosSystem
filterAttrs
attrByPath
foldlAttrs
;

flattenAttrs = {
prefix ? [],
sep ? ".",
}: x: let
f = path:
foldlAttrs (acc: name: value:
(
if isAttrs value
then (f "${path}${name}${sep}" value)
else {"${path}${name}" = value;}
)
// acc) {};
in
f (
if prefix == []
then ""
else (concatStringsSep sep prefix) + sep
)
x;

importProjects = {
pkgs ? {},
lib ? inputs.nixpkgs.lib,
sources ? {},
}:
import ./projects {inherit lib pkgs sources;};

mapAttrByPath = attrPath: default: mapAttrs (_: attrByPath attrPath default);

pickNixosModules = mapAttrByPath ["nixos" "modules"] {};

pickPackages = mapAttrByPath ["packages"] {};

pickNixosTests = mapAttrByPath ["nixos" "tests"] {};

pickNixosConfigurations = x: mapAttrs (_: v: mapAttrs (_: v: v.path) v) (mapAttrByPath ["nixos" "configurations"] {} x);

importPackages = pkgs: let
nixosTests = let
dir = ./tests;
testDirs = readDir dir;

dirToTest = name: _: let
mkTestModule = import "${dir}/${name}";

testModule = mkTestModule {
inherit pkgs;
inherit (pkgs) lib;
modules = extendedModules;
configurations = rawNixosConfigs;
};
in
pkgs.nixosTest testModule;
in
mapAttrs dirToTest testDirs;
nixosTests = pickNixosTests (importProjects {
inherit pkgs;
lib = inputs.nixpkgs.lib;
sources.configurations = rawNixosConfigs;
sources.modules = extendedModules;
});

callPackage = pkgs.newScope (
allPackages // {inherit callPackage nixosTests;}
Expand All @@ -87,10 +115,13 @@
importNixpkgs = system: overlays:
import nixpkgs {inherit system overlays;};

rawNixosConfigs = import ./configs/all-configurations.nix;
rawNixosConfigs = flattenAttrs {sep = "/";} (pickNixosConfigurations (importProjects {}));

loadTreefmt = pkgs: treefmt-nix.lib.evalModule pkgs ./treefmt.nix;

# Overlays a package set (e.g. nixpkgs) with the packages defined in this flake.
overlay = final: prev: importPackages prev;

# Attribute set containing all modules obtained via `inputs` and defined
# in this flake towards definition of `nixosConfigurations` and `nixosTests`.
extendedModules =
Expand All @@ -101,13 +132,13 @@

nixosConfigurations =
mapAttrs
(_: config: nixosSystem {modules = [config ./configs/dummy.nix] ++ attrValues extendedModules;})
(_: config: nixosSystem {modules = [config ./dummy.nix] ++ attrValues extendedModules;})
rawNixosConfigs;

eachDefaultSystemOutputs = flake-utils.lib.eachDefaultSystem (system: let
pkgs = importNixpkgs system [rust-overlay.overlays.default];
treefmtEval = loadTreefmt pkgs;
toplevel = name: config: nameValuePair "nixosConfigs/${name}" config.config.system.build.toplevel;
toplevel = name: config: nameValuePair "nixosConfigurations/${name}" config.config.system.build.toplevel;

importPack = importPackages pkgs;

Expand Down Expand Up @@ -205,14 +236,23 @@

nixosModules =
(import ./modules/all-modules.nix)
// (
flattenAttrs {sep = "/";} (pickNixosModules (importProjects {
sources = {
inherit inputs;
inherit self;
modules = extendedModules;
configurations = rawNixosConfigs;
};
}))
)
// {
# The default module adds the default overlay on top of nixpkgs.
# This is so that `ngipkgs` can be used alongside `nixpkgs` in a configuration.
default.nixpkgs.overlays = [self.overlays.default];
};

# Overlays a package set (e.g. nixpkgs) with the packages defined in this flake.
overlays.default = final: prev: importPackages prev;
overlays.default = overlay;
};
in
foldr recursiveUpdate {} [
Expand Down
File renamed without changes.
7 changes: 0 additions & 7 deletions modules/all-modules.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
{
# LiberaForms is intentionally disabled.
# Refer to <https://github.com/ngi-nix/ngipkgs/issues/40>.
#liberaforms = import ./liberaforms.nix;
flarum = import ./flarum.nix;
kbin = import ./kbin.nix;
mcaptcha = import ./mcaptcha.nix;
pretalx = import ./pretalx.nix;
unbootable = import ./unbootable.nix;
}
6 changes: 3 additions & 3 deletions pkgs/by-name/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@

packageDirectories = concatMapAttrs names (readDir baseDirectory);

callModule = moduleDir: let
callModule = module: let
evaluated = lib.evalModules {
specialArgs = {
inherit dream2nix;
packageSets.nixpkgs = pkgs;
};
modules = [
moduleDir
module
{
paths.projectRoot = ../..;
paths.projectRootFile = "flake.nix";
paths.package = moduleDir;
paths.package = module;
paths.lockFile = "lock.json";
}
];
Expand Down
4 changes: 0 additions & 4 deletions pkgs/by-name/flarum/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,5 @@ php.buildComposerProject (finalAttrs: {
description = "Flarum is a delightfully simple discussion platform for your website";
homepage = "https://github.com/flarum/flarum";
license = lib.licenses.mit;
ngi = {
project = "Flarum";
options = [["services" "flarum"]];
};
};
})
6 changes: 1 addition & 5 deletions pkgs/by-name/kbin/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ runCommand "kbin" {
kbin-backend.passthru
// {
tests = {
inherit (nixosTests) kbin;
inherit (nixosTests.Kbin) kbin;
};
};
meta = {
license = lib.licenses.agpl3Only;
homepage = "https://kbin.pub/";
description = "/kbin is a modular, decentralized content aggregator and microblogging platform running on the Fediverse network.";
ngi = {
project = "Kbin";
options = [["services" "kbin"]];
};
};
} ''
# As of 2023-10-09, there is no way to just symlink
Expand Down
3 changes: 1 addition & 2 deletions pkgs/by-name/mcaptcha-cache/package.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
rustPlatform,
fetchFromGitHub,
lib,
}: let
src = fetchFromGitHub {
owner = "mCaptcha";
Expand All @@ -13,7 +12,7 @@
sha256 = "sha256-whRLgYkoBoVQiZwrmwBwqgHzPqqXC6g3na3YrH4/xVo=";
};
in
rustPlatform.buildRustPackage rec {
rustPlatform.buildRustPackage {
inherit src;
pname = "cache";
version = "unstable-2023-03-08";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/by-name/mcaptcha/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
mainProgram = "mcaptcha";
};

passthru.tests = {inherit (nixosTests) mcaptcha-create-locally mcaptcha-bring-your-own-services;};
passthru.tests = {inherit (nixosTests.mCaptcha) create-locally bring-your-own-services;};
};
in
mcaptcha
6 changes: 1 addition & 5 deletions pkgs/by-name/rosenpass/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ in
installManPage doc/rosenpass.1
'';

passthru.tests.rosenpass = nixosTests.rosenpass;
passthru.tests.rosenpass = nixosTests.Rosenpass.rosenpass;

meta = {
description = "Build post-quantum-secure VPNs with WireGuard!";
Expand All @@ -63,9 +63,5 @@ in
maintainers = with maintainers; [wucke13];
platforms = ["aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux"];
mainProgram = "rosenpass";
ngi = {
project = "Rosenpass";
options = [["services" "rosenpass"]];
};
};
}
6 changes: 1 addition & 5 deletions pkgs/pretalx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ in
inherit python;
PYTHONPATH = "${python.pkgs.makePythonPath propagatedBuildInputs}:${pretalx.outPath}/${python.sitePackages}";

tests.pretalx = nixosTests.pretalx;
tests.pretalx = nixosTests.Pretalx.pretalx;
};

meta = {
Expand All @@ -185,9 +185,5 @@ in
lorenzleutgeb
]
++ (with (import ../../maintainers/maintainers-list.nix); [augustebaum kubaneko]);
ngi = {
project = "Pretalx";
options = [["services" "pretalx"]];
};
};
}
File renamed without changes.
7 changes: 7 additions & 0 deletions projects/Flarum/project.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{pkgs, ...}: {
packages =
if pkgs == {}
then builtins.throw "wut?"
else {inherit (pkgs) flarum;};
nixos.module.service = ./service.nix;
}
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions projects/Kbin/project.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
pkgs,
lib,
...
} @ args: {
packages = {inherit (pkgs) kbin kbin-frontend kbin-backend;};
nixos = rec {
modules.service = ./service.nix;
configurations = {
base = {
path = ./configuration.nix;
description = "Basic configuration, mainly used for testing purposes.";
};
};
tests.kbin = import ./test.nix (lib.recursiveUpdate args {
sources.configurations.kbin = configurations.base.path;
});
};
}
File renamed without changes.
11 changes: 5 additions & 6 deletions tests/kbin/default.nix → projects/Kbin/test.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
configurations,
modules,
sources,
lib,
...
}: let
Expand All @@ -18,10 +17,10 @@ in {
...
}: {
imports = [
modules.default
modules.kbin
modules.unbootable
configurations.kbin
sources.modules.default
sources.modules."Kbin/service"
sources.modules.unbootable
sources.configurations.kbin
];

unbootable = mkForce false;
Expand Down
5 changes: 5 additions & 0 deletions projects/LiberaForms-E2EE/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# LiberaForms

Intentionally disabled.

Refer to <https://github.com/ngi-nix/ngipkgs/issues/40>.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
pretalx.database = {
backend = "mysql";
host = "/var/run/mysqld/mysqld.sock";
user = "pretalx";
};

mysql = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{config, ...}: {
services = {
pretalx.database.backend = "postgresql";
pretalx.database = {
backend = "postgresql";
user = "pretalx";
};

postgresql = {
enable = true;
authentication = "local all all trust";
ensureUsers = [
{
name = config.services.pretalx.database.user;
ensurePermissions."DATABASE \"${config.services.pretalx.database.name}\"" = "ALL PRIVILEGES";
ensureDBOwnership = true;
}
];
ensureDatabases = [config.services.pretalx.database.name];
Expand Down
Loading

0 comments on commit 186e149

Please sign in to comment.