hydra-config/hail.nix

51 lines
1.7 KiB
Nix
Raw Normal View History

2019-11-06 21:44:39 +01:00
{ pkgs ? import <nixpkgs> { config.allowBroken = true; },
}:
with pkgs;
let
physicalHost = host: {
inherit host;
2019-11-06 21:59:50 +01:00
configuration = <nix-config> + "/hosts/${host}/configuration.nix";
2019-11-06 21:44:39 +01:00
};
containerHost = host: {
inherit host;
configuration = <nix-config> + "/hosts/containers/${host}/configuration.nix";
};
physicalHosts =
2019-11-06 21:58:03 +01:00
lib.mapAttrsToList (host: _: physicalHost host) (
2019-11-06 21:44:39 +01:00
lib.filterAttrs (host: ty: ty == "directory" && host != "containers") (
builtins.readDir (<nix-config> + "/hosts")
));
containerHosts =
lib.mapAttrsToList (host: _: containerHost host) (
lib.filterAttrs (_: ty: ty == "directory") (
builtins.readDir (<nix-config> + "/hosts/containers")
));
hosts = containerHosts ++ physicalHosts;
hostSpec = { host, configuration }: rec {
# pkgs.nixos consumes a NixOS configuration. The toplevel attribute of its return set
# contains the switch-to-configuration script that is also usually called by nixos-rebuild
config = (pkgs.nixos configuration).toplevel;
# hail expects an activator script in `$out/bin/activate`. We let it run the
# switch-to-configuration script with systemd, because if hail is updated
# itself while switching, it would be killed during the switch
activator = pkgs.writeScriptBin "activate" ''
exec -a systemd-run ${pkgs.systemd}/bin/systemd-run \
--description "Hail: Activate new configuration" \
${config}/bin/switch-to-configuration switch
'';
};
in
builtins.listToAttrs (
builtins.concatMap (spec:
let
part = p: {
name = "${spec.host}-${p}";
value = (hostSpec spec).${p};
};
in
[ (part "config") (part "activator") ]
) hosts
)