1
1
forked from extern/flakelight

Automatically find and load nix files for flake attrs

This commit is contained in:
Archit Gupta 2023-04-15 03:38:28 -07:00
parent ec3ce2b4aa
commit 58503515fb

View File

@ -47,6 +47,46 @@ let
}; };
}; };
autoAttrs = src:
let
loadAttr = attr:
if pathExists (src + "/nix/${attr}.nix")
then import (src + "/nix/${attr}.nix")
else if pathExists (src + "/nix/${attr}/default.nix")
then import (src + "/nix/${attr}")
else if pathExists (src + "/nix/${attr}")
then loadNixDir (src + "/nix/${attr}")
else if pathExists (src + "/${attr}.nix")
then import (src + "/${attr}.nix")
else if pathExists (src + "/${attr}/default.nix")
then import (src + "/${attr}")
else if pathExists (src + "/${attr}")
then loadNixDir (src + "/${attr}")
else null;
attrs = [
"withOverlay"
"withOverlays"
"package"
"packages"
"devTools"
"devShell"
"devShells"
"env"
"overlay"
"overlays"
"apps"
"checks"
"nixosModules"
"nixosConfigurations"
"templates"
"formatters"
"systems"
"perSystem"
"outputs"
];
in
filterAttrs (_: v: v != null) (genAttrs attrs loadAttr);
mkFlake = src: inputs: root: mkFlake = src: inputs: root:
let let
modules = root.modules or pipe (inputs // { self = { }; }) [ modules = root.modules or pipe (inputs // { self = { }; }) [
@ -106,11 +146,15 @@ let
formatters = mkFunc module'.formatters; formatters = mkFunc module'.formatters;
}; };
root' = normalizeModule root // { root' =
systems = applyParams root.systems or systems.linuxDefault; let
perSystem = mkFunc root.perSystem or (_: { }); rootWithAuto = (autoAttrs src) // root;
outputs = applyParams root.outputs or { }; in
}; normalizeModule rootWithAuto // {
systems = applyParams rootWithAuto.systems or systems.linuxDefault;
perSystem = mkFunc rootWithAuto.perSystem or (_: { });
outputs = applyParams rootWithAuto.outputs or { };
};
mergeModules = m1: m2: { mergeModules = m1: m2: {
withOverlays = m1.withOverlays ++ m2.withOverlays; withOverlays = m1.withOverlays ++ m2.withOverlays;