From c0c9602a6be5d557bc684efc027310237a631901 Mon Sep 17 00:00:00 2001 From: Astro Date: Wed, 6 Nov 2019 21:44:39 +0100 Subject: [PATCH] hail: init --- hail.nix | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ jobsets.nix | 8 ++++++++ 2 files changed, 58 insertions(+) create mode 100644 hail.nix diff --git a/hail.nix b/hail.nix new file mode 100644 index 0000000..5fbf937 --- /dev/null +++ b/hail.nix @@ -0,0 +1,50 @@ +{ pkgs ? import { config.allowBroken = true; }, +}: + +with pkgs; +let + physicalHost = host: { + inherit host; + configuration = + "/containers/${host}/configuration.nix"; + }; + containerHost = host: { + inherit host; + configuration = + "/hosts/containers/${host}/configuration.nix"; + }; + physicalHosts = + lib.mapAttrsToList (host: _: containerHost host) ( + lib.filterAttrs (host: ty: ty == "directory" && host != "containers") ( + builtins.readDir ( + "/hosts") + )); + containerHosts = + lib.mapAttrsToList (host: _: containerHost host) ( + lib.filterAttrs (_: ty: ty == "directory") ( + builtins.readDir ( + "/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 + ) diff --git a/jobsets.nix b/jobsets.nix index 794ae6f..17f75e4 100644 --- a/jobsets.nix +++ b/jobsets.nix @@ -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 );