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:
parent
f510679c2f
commit
9a9524a71e
1 changed files with 62 additions and 64 deletions
126
flake.nix
126
flake.nix
|
@ -166,77 +166,75 @@
|
||||||
extraSpecialArgs = { inherit inputs outputs; };
|
extraSpecialArgs = { inherit inputs outputs; };
|
||||||
};
|
};
|
||||||
|
|
||||||
# Final configurations
|
|
||||||
|
|
||||||
|
createConfigurations =
|
||||||
|
pred: mkHost: machines:
|
||||||
|
nixpkgs.lib.foldAttrs
|
||||||
|
(acc: x: acc)
|
||||||
|
[]
|
||||||
|
(builtins.attrValues
|
||||||
|
(builtins.mapAttrs
|
||||||
|
(system: hosts:
|
||||||
|
nixpkgs.lib.attrsets.filterAttrs
|
||||||
|
(host: config: config != null)
|
||||||
|
(builtins.mapAttrs
|
||||||
|
(host: config:
|
||||||
|
if (pred system host config)
|
||||||
|
then mkHost system host config
|
||||||
|
else null)
|
||||||
|
hosts))
|
||||||
|
machines));
|
||||||
|
|
||||||
|
# Final configurations
|
||||||
nixosConfigurations =
|
nixosConfigurations =
|
||||||
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
|
mkNixosHost
|
||||||
(host: config: config != null)
|
system
|
||||||
(builtins.mapAttrs
|
host)
|
||||||
(host: config:
|
nixosMachines;
|
||||||
if (hasFiles [ "configuration.nix" ] config)
|
|
||||||
then mkNixosHost system host
|
|
||||||
else null)
|
|
||||||
hosts))
|
|
||||||
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:
|
(builtins.map
|
||||||
if (hasFiles [ "configuration.nix" ] config)
|
(nixpkgs.lib.strings.removeSuffix ".nix")
|
||||||
then mkNixDarwinHost system host
|
(builtins.attrNames (config."home" or {}))))
|
||||||
(builtins.map
|
nixDarwinMachines;
|
||||||
(nixpkgs.lib.strings.removeSuffix ".nix")
|
|
||||||
(builtins.attrNames (config."home" or {})))
|
|
||||||
else null)
|
|
||||||
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));
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue