base/export/nixosConfigurations.nix

67 lines
1.8 KiB
Nix

{
nixosUsers ? { },
nixosGroups ? { },
nixosModules,
hmModules ? {
default = { };
},
...
}@flake:
{ ... }@inputs:
{ host, ... }@imports:
let
pre-switch-check =
{ pkgs, lib, config, ... }:
{
config.system.preSwitchChecks.nvd = ''
nvd_check=y
if [[ -d /run/current-system ]]
then
${lib.getExe pkgs.nvd} --nix-bin-dir ${config.nix.package}/bin diff /run/current-system "''${1}"
if [[ -t 0 ]]; then
printf 'really %s to %s? [y]es/[N]o ' "''${2}" "''${1}"
read -r nvd_check
fi
fi
[[ "''${nvd_check}" == y ]]
'';
};
system =
hostname:
{
namespace ? "fbs42",
nixpkgs ? "nixpkgs",
classes ? [ hostname ],
}:
inputs.${nixpkgs}.lib.nixosSystem {
specialArgs = { inherit inputs flake namespace; };
modules =
builtins.concatLists (
map (
base: builtins.attrValues (flake.lib.scan { base = "${base}/host/${hostname}"; })
) flake.lib.schema.base
)
++ map (class: {
imports = map (input: input.${namespace}.${class} or { }) (builtins.attrValues inputs);
}) classes
++ [ pre-switch-check ]
++ [ { config.networking.hostName = hostname; } ]
++ [ nixosModules.default ]
++ inputs.${nixpkgs}.lib.optional (inputs ? home-manager) {
imports = [ inputs.home-manager.nixosModules.default ];
config.home-manager = {
sharedModules = [ hmModules.default ];
extraSpecialArgs = { inherit flake namespace; };
};
}
++ builtins.attrValues nixosUsers
++ builtins.attrValues nixosGroups;
};
in
builtins.mapAttrs (
name: value:
assert builtins.length value == 1;
system name (builtins.head value)
) host