hydra-config/hail.nix

62 lines
2.0 KiB
Nix
Raw Permalink Normal View History

2019-11-06 21:44:39 +01:00
{ pkgs ? import <nixpkgs> { config.allowBroken = true; },
}:
with pkgs;
let
# TODO: make these work in restricted mode
blacklist = {
mucbot = true;
2019-11-06 22:20:10 +01:00
spaceapi = true;
2019-11-09 14:59:17 +01:00
storage-ng = true; # missing secrets submodule
2019-11-29 14:02:52 +01:00
server7 = true;
};
2019-11-06 21:44:39 +01:00
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}";
2019-11-06 22:02:57 +01:00
value = lib.hydraJob (hostSpec spec).${p};
2019-11-06 21:44:39 +01:00
};
in
[ (part "config") (part "activator") ]
) (
builtins.filter ({ host, ... }:
! (builtins.hasAttr host blacklist)
) hosts
)
2019-11-06 21:44:39 +01:00
)