diff --git a/lib/collect-flake-inputs.nix b/lib/collect-flake-inputs.nix new file mode 100644 index 00000000..0803ad6f --- /dev/null +++ b/lib/collect-flake-inputs.nix @@ -0,0 +1,10 @@ +flake: let + collectFlakeInputs = input: + [input] + ++ builtins.concatMap collectFlakeInputs ( + builtins.attrValues ( + input.inputs or {} + ) + ); +in + collectFlakeInputs flake diff --git a/lib/configurations.nix b/lib/configurations.nix index af597d5c..106d68b4 100644 --- a/lib/configurations.nix +++ b/lib/configurations.nix @@ -8,7 +8,7 @@ builtins.listToAttrs ( specialArgs = inputs // { - inherit (inputs.self.lib) hmModule; + inherit (inputs.self.lib) flakeInputsClosure hmModule; inherit box; }; }; diff --git a/lib/default.nix b/lib/default.nix index bd7cb776..b307cdfc 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,4 +1,6 @@ inputs: { + flakeInputsClosure = import ./collect-flake-inputs.nix inputs.self; + boxen = import ./boxen.nix inputs; fmt-alejandra = import ./fmt-alejandra.nix inputs; diff --git a/modules/traits/flake-sources/default.nix b/modules/traits/flake-sources/default.nix new file mode 100644 index 00000000..d9bfa571 --- /dev/null +++ b/modules/traits/flake-sources/default.nix @@ -0,0 +1,16 @@ +{ + config, + lib, + flakeInputsClosure, + ... +}: let + cfg = config.traits.flake-sources; +in { + options.traits.flake-sources = { + enable = lib.mkEnableOption "flake inputs as GC roots (recursively)" // {default = true;}; + }; + + config = lib.mkIf cfg.enable { + system.extraDependencies = flakeInputsClosure; + }; +}