feat(flake): refactor configuration definitions

Now a bunch of configurations may be created from two functions and a set:
    `pred` - a validator that says whether a configuration is valid
    `mkHost` - a generator for that system's configuration
    `machines` - a nested attrset containing all the info for the machines
This commit is contained in:
reo101 2022-11-27 15:18:40 +02:00
parent f510679c2f
commit 9a9524a71e

100
flake.nix
View file

@ -166,9 +166,9 @@
extraSpecialArgs = { inherit inputs outputs; }; extraSpecialArgs = { inherit inputs outputs; };
}; };
# Final configurations
nixosConfigurations = createConfigurations =
pred: mkHost: machines:
nixpkgs.lib.foldAttrs nixpkgs.lib.foldAttrs
(acc: x: acc) (acc: x: acc)
[] []
@ -179,64 +179,62 @@
(host: config: config != null) (host: config: config != null)
(builtins.mapAttrs (builtins.mapAttrs
(host: config: (host: config:
if (hasFiles [ "configuration.nix" ] config) if (pred system host config)
then mkNixosHost system host then mkHost system host config
else null) else null)
hosts)) hosts))
nixosMachines)); machines));
# Final configurations
nixosConfigurations =
createConfigurations
(system: host: config:
hasFiles
[ "configuration.nix" ]
config)
(system: host: config:
mkNixosHost
system
host)
nixosMachines;
nixOnDroidConfigurations = nixOnDroidConfigurations =
nixpkgs.lib.foldAttrs createConfigurations
(acc: x: acc) (system: host: config:
[] hasFiles
(builtins.attrValues [ "configuration.nix" "home.nix" ]
(builtins.mapAttrs config)
(system: hosts: (system: host: config:
nixpkgs.lib.attrsets.filterAttrs mkNixOnDroidHost
(host: config: config != null) system
(builtins.mapAttrs host)
(host: config: nixOnDroidMachines;
if (hasFiles [ "configuration.nix" "home.nix" ] config)
then mkNixOnDroidHost system host
else null)
hosts))
nixOnDroidMachines));
darwinConfigurations = darwinConfigurations =
nixpkgs.lib.foldAttrs createConfigurations
(acc: x: acc) (system: host: config:
[] hasFiles
(builtins.attrValues [ "configuration.nix" ]
(builtins.mapAttrs config)
(system: hosts: (system: host: config:
nixpkgs.lib.attrsets.filterAttrs mkNixDarwinHost
(host: config: config != null) system
(builtins.mapAttrs host
(host: config:
if (hasFiles [ "configuration.nix" ] config)
then mkNixDarwinHost system host
(builtins.map (builtins.map
(nixpkgs.lib.strings.removeSuffix ".nix") (nixpkgs.lib.strings.removeSuffix ".nix")
(builtins.attrNames (config."home" or {}))) (builtins.attrNames (config."home" or {}))))
else null) nixDarwinMachines;
hosts))
nixDarwinMachines));
homeConfigurations = homeConfigurations =
nixpkgs.lib.foldAttrs createConfigurations
(acc: x: acc) (system: host: config:
[] hasFiles
(builtins.attrValues [ "home.nix" ]
(builtins.mapAttrs config)
(system: hosts: (system: host: config:
nixpkgs.lib.attrsets.filterAttrs mkHomeManagerHost
(host: config: config != null) system
(builtins.mapAttrs host)
(host: config: homeManagerMachines;
if (hasFiles [ "home.nix" ] config)
then mkNixOnDroidHost system host
else null)
hosts))
homeManagerMachines));
}; };
} }