hail: init

This commit is contained in:
Astro 2019-11-06 21:44:39 +01:00
parent 09b022a9f5
commit c0c9602a6b
2 changed files with 58 additions and 0 deletions

50
hail.nix Normal file
View File

@ -0,0 +1,50 @@
{ pkgs ? import <nixpkgs> { config.allowBroken = true; },
}:
with pkgs;
let
physicalHost = host: {
inherit host;
configuration = <nix-config> + "/containers/${host}/configuration.nix";
};
containerHost = host: {
inherit host;
configuration = <nix-config> + "/hosts/containers/${host}/configuration.nix";
};
physicalHosts =
lib.mapAttrsToList (host: _: containerHost host) (
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
)

View File

@ -109,6 +109,14 @@ let
registry = "https://git.dn42.us/dn42/registry.git";
};
};
hail = mkJobset {
description = "NixOS builds for deployment through Hail";
nixexprpath = "hail.nix";
gitUrls = {
nix-config = "https://gitea.c3d2.de/C3D2/nix-config.git";
};
};
};
jobsetsJson = pkgs.writeText "jobsets.json" (builtins.toJSON jobsets );