diff --git a/flake.nix b/flake.nix index 435f37dd..c7ac70fb 100644 --- a/flake.nix +++ b/flake.nix @@ -47,7 +47,6 @@ recursiveUpdate nameValuePair filterAttrs - attrByPath ; inherit @@ -65,15 +64,12 @@ } // args); - # NGI packages are imported from ./pkgs/by-name/default.nix. - importNgiPackages = pkgs: + overlay = final: prev: import ./pkgs/by-name { - inherit (pkgs) lib; - inherit dream2nix pkgs; + pkgs = prev; + inherit lib dream2nix; }; - overlay = final: prev: importNgiPackages prev; - # NGI projects are imported from ./projects/default.nix. # Each project includes packages, and optionally, modules, examples and tests. @@ -140,20 +136,12 @@ eachDefaultSystemOutputs = flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; - overlays = [ - overlay - ]; + overlays = [overlay]; }; - ngiPackages = importNgiPackages pkgs; - - # Dream2nix is failing to pass through the meta attribute set. - # As a workaround, consider packages with empty meta as non-broken. - nonBrokenNgiPackages = filterAttrs (_: v: !(attrByPath ["meta" "broken"] false v)) ngiPackages; + ngipkgs = import ./pkgs/by-name {inherit pkgs lib dream2nix;}; - ngiProjects = importNgiProjects (pkgs // ngiPackages); - - nonBrokenNgiProjects = importNgiProjects (pkgs // nonBrokenNgiPackages); + ngiProjects = importNgiProjects (pkgs // ngipkgs); optionsDoc = pkgs.nixosOptionsDoc { options = @@ -180,7 +168,7 @@ }; packages = - ngiPackages + ngipkgs // { overview = import ./overview { inherit lib pkgs self; @@ -217,28 +205,28 @@ (checksForNixosTests projectName (project.nixos.tests or {})) // (checksForNixosExamples projectName (project.nixos.examples or {})); - checksForAllProjects = - concatMapAttrs - checksForProject - nonBrokenNgiProjects; - checksForPackageDerivation = packageName: package: {"packages/${packageName}" = package;}; - checksForPackagePassthruTests = packageName: tests: (concatMapAttrs (passthruName: test: {"packages/${packageName}/passthru/${passthruName}" = test;}) tests); + checksForPackagePassthruTests = packageName: tests: + concatMapAttrs + (passthruName: test: {"packages/${packageName}/passthru/${passthruName}" = test;}) + tests; checksForPackage = packageName: package: (checksForPackageDerivation packageName package) // (checksForPackagePassthruTests packageName (package.passthru.tests or {})); - checksForAllPackages = - concatMapAttrs - checksForPackage - nonBrokenNgiPackages; - in - checksForAllProjects - // checksForAllPackages - // { - pre-commit = pre-commit-hooks.lib.${system}.run { + # everything must evaluate for checks to run + nonBrokenPackages = filterAttrs (_: v: ! v.meta.broken or false) ngipkgs; + + checksForAllProjects = + concatMapAttrs checksForProject + (importNgiProjects (pkgs // nonBrokenPackages)); + + checksForAllPackages = concatMapAttrs checksForPackage nonBrokenPackages; + + checksForInfrastructure = { + "infra/pre-commit" = pre-commit-hooks.lib.${system}.run { src = ./.; hooks = { actionlint.enable = true; @@ -248,9 +236,13 @@ "infra/makemake" = toplevel self.nixosConfigurations.makemake; "infra/overview" = self.packages.${system}.overview; }; + in + checksForInfrastructure + // checksForAllProjects + // checksForAllPackages; devShells.default = pkgs.mkShell { - inherit (checks.pre-commit) shellHook; + inherit (checks."infra/pre-commit") shellHook; buildInputs = checks.pre-commit.enabledPackages; }; @@ -259,7 +251,7 @@ text = '' # shellcheck disable=all shell-hook () { - ${checks.pre-commit.shellHook} + ${checks."infra/pre-commit".shellHook} } shell-hook @@ -268,8 +260,5 @@ }; }); in - foldr recursiveUpdate {} [ - eachDefaultSystemOutputs - systemAgnosticOutputs - ]; + eachDefaultSystemOutputs // systemAgnosticOutputs; } diff --git a/pkgs/by-name/default.nix b/pkgs/by-name/default.nix index 1e771406..a422dc54 100644 --- a/pkgs/by-name/default.nix +++ b/pkgs/by-name/default.nix @@ -1,33 +1,37 @@ { + pkgs, lib, dream2nix, - pkgs, }: let - baseDirectory = ./.; - inherit (builtins) + elem pathExists readDir ; inherit (lib.attrsets) - mapAttrs concatMapAttrs + mapAttrs ; - names = name: type: - if type != "directory" - then assert name == "README.md" || name == "default.nix"; {} - else {${name} = baseDirectory + "/${name}";}; + baseDirectory = ./.; - packageDirectories = concatMapAttrs names (readDir baseDirectory); + packageDirectories = let + names = name: type: + if type == "directory" + then {${name} = baseDirectory + "/${name}";} + # nothing else should be kept in this directory reserved for derivations + else assert elem name allowedFiles; {}; + allowedFiles = ["README.md" "default.nix"]; + in + concatMapAttrs names (readDir baseDirectory); callModule = module: let evaluated = lib.evalModules { specialArgs = { - dream2nix = import dream2nix; + inherit dream2nix; packageSets.nixpkgs = pkgs; }; modules = [ @@ -48,7 +52,8 @@ ); self = - mapAttrs ( + mapAttrs + ( _: directory: if pathExists (directory + "/package.nix") then callPackage (directory + "/package.nix") {} diff --git a/projects/default.nix b/projects/default.nix index 73caedb2..69b8efe7 100644 --- a/projects/default.nix +++ b/projects/default.nix @@ -12,21 +12,23 @@ inherit (lib.attrsets) + concatMapAttrs + filterAttrs mapAttrs recursiveUpdate - filterAttrs ; baseDirectory = ./.; - allowedFiles = ["README.md" "default.nix"]; - - isMarkedBroken = project: project.broken or false; - - filter = name: type: - if type != "directory" - then assert elem name allowedFiles; false - else true; + projectDirectories = let + names = name: type: + if type == "directory" + then {${name} = baseDirectory + "/${name}";} + # nothing else should be kept in this directory reserved for projects + else assert elem name allowedFiles; {}; + allowedFiles = ["README.md" "default.nix"]; + in + concatMapAttrs names (readDir baseDirectory); nixosTest = test: let # Amenities for interactive tests @@ -49,13 +51,13 @@ project {nixos.tests = mapAttrs (_: nixosTest) project.nixos.tests or {};}; in - mapAttrs ( - name: type: let - project = import (baseDirectory + "/${name}") { - inherit lib pkgs sources; - }; + mapAttrs + ( + name: directory: let + project = import directory {inherit lib pkgs sources;}; in - if isMarkedBroken project + if project.broken or false then trace "Skipping project '${name}' which is marked as broken for system '${pkgs.system or "undefined"}'." {} else hydrate project - ) (filterAttrs filter (readDir baseDirectory)) + ) + projectDirectories