refactor(nixos): change hostSpec to define top level option
This commit is contained in:
parent
6aa5096172
commit
b43476ccee
3 changed files with 31 additions and 29 deletions
28
modules/configurations/nixos.nix
Normal file
28
modules/configurations/nixos.nix
Normal file
|
@ -0,0 +1,28 @@
|
|||
{ config, lib, ... }:
|
||||
let
|
||||
inherit (lib.trivial) pipe;
|
||||
inherit (lib.attrsets) filterAttrs mapAttrs';
|
||||
inherit (lib.strings) removePrefix hasPrefix;
|
||||
prefix = "nixos/";
|
||||
hosts = config.flake.hostSpec.hosts or { };
|
||||
mkSystem =
|
||||
name: value:
|
||||
let
|
||||
hostName = removePrefix prefix name;
|
||||
in
|
||||
{
|
||||
name = hostName;
|
||||
value = lib.nixosSystem {
|
||||
modules = [
|
||||
value
|
||||
{ networking = { inherit hostName; }; }
|
||||
];
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
flake.nixosConfigurations = pipe hosts [
|
||||
(filterAttrs (name: _: hasPrefix prefix name))
|
||||
(mapAttrs' mkSystem)
|
||||
];
|
||||
}
|
3
modules/hostSpec.nix
Normal file
3
modules/hostSpec.nix
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
flake.hostSpec.hosts = { };
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (builtins) mapAttrs;
|
||||
inherit (lib) mkOption;
|
||||
inherit (lib.types) lazyAttrsOf submodule;
|
||||
cfg = config.hostSpec;
|
||||
hostOptions = submodule { };
|
||||
mkSystem =
|
||||
hostName: _hostConfig:
|
||||
inputs.nixpkgs.lib.nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
modules = [ { networking = { inherit hostName; }; } ];
|
||||
};
|
||||
in
|
||||
{
|
||||
options.hostSpec.hosts = mkOption {
|
||||
type = lazyAttrsOf hostOptions;
|
||||
default = { };
|
||||
};
|
||||
|
||||
config = {
|
||||
flake.nixosConfigurations = mapAttrs mkSystem cfg.hosts;
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue