diff options
1 files changed, 48 insertions, 3 deletions
| -rw-r--r-- | autoconfig.nix | 51 |
diff --git a/autoconfig.nix b/autoconfig.nix index 5460362..74424f1 100644 --- a/autoconfig.nix +++ b/autoconfig.nix @@ -1,7 +1,22 @@ -{ inputs, ... }: +{ self, inputs, ... }: let inherit (inputs) nixpkgs; inherit (nixpkgs) lib; + _mergeAttrs = + let + recurse = attrset: + lib.zipAttrsWith + (name: values: + if builtins.isAttrs (builtins.head values) then + recurse (builtins.filter (val: builtins.isAttrs val) values) + else if builtins.isList (builtins.head values) then + lib.concatLists (builtins.filter (val: builtins.isList val) values) + else + lib.last values + ) + attrset; + in + recurse; in { configurations = lib.mapAttrs @@ -13,8 +28,38 @@ in { modules = [ ./machines/${dir}/hardware-configuration.nix ./configuration.nix + self.packages ]; - } - ) + }) (lib.filterAttrs (_: type: type == "directory") (builtins.readDir ./machines)); + + packages = + let + package-groups = import ./packages/default.nix { inherit nixpkgs; }; + in + lib.foldlAttrs + (config: _: package-group: + let + config-from-group = + lib.foldlAttrs + (acc: pkg-name: pkg-settings: + if pkg-name == "list" then + _mergeAttrs [ + acc + { + environment.systemPackages = pkg-settings; + }] + else + _mergeAttrs [ + acc + (lib.filterAttrs (name: _: name != "ref") pkg-settings) + { + environment.systemPackages = [pkg-settings.ref]; + }]) + {} + package-group; + in + _mergeAttrs [config config-from-group]) + {} + package-groups; # TODO: filter on machine type } |
