2021-04-11 22:50:30 +02:00
|
|
|
# Helper functions for instantiating depot-compatible NixOS machines.
|
2021-04-10 13:40:06 +02:00
|
|
|
{ depot, lib, pkgs, ... }@args:
|
2020-07-02 20:19:08 +02:00
|
|
|
|
2021-04-10 18:05:16 +02:00
|
|
|
let inherit (lib) findFirst isAttrs;
|
2021-04-10 13:40:06 +02:00
|
|
|
in rec {
|
2021-04-02 14:13:08 +02:00
|
|
|
# This provides our standard set of arguments to all NixOS modules.
|
|
|
|
baseModule = { ... }: {
|
|
|
|
_module.args = {
|
|
|
|
inherit (args) depot;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-04-10 18:05:16 +02:00
|
|
|
nixosFor = configuration: (depot.third_party.nixos {
|
2021-04-02 14:13:08 +02:00
|
|
|
configuration = { ... }: {
|
2020-11-22 20:35:31 +01:00
|
|
|
imports = [
|
2021-04-02 14:13:08 +02:00
|
|
|
baseModule
|
2020-11-22 20:35:31 +01:00
|
|
|
configuration
|
|
|
|
];
|
|
|
|
};
|
2021-04-02 14:13:08 +02:00
|
|
|
});
|
2020-07-03 06:26:33 +02:00
|
|
|
|
|
|
|
findSystem = hostname:
|
|
|
|
(findFirst
|
|
|
|
(system: system.config.networking.hostName == hostname)
|
|
|
|
(throw "${hostname} is not a known NixOS host")
|
2021-04-11 22:50:30 +02:00
|
|
|
(map nixosFor depot.ops.machines.all-systems));
|
2020-07-03 06:26:33 +02:00
|
|
|
|
|
|
|
rebuild-system = pkgs.writeShellScriptBin "rebuild-system" ''
|
|
|
|
set -ue
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
|
|
echo "Oh no! Only root is allowed to rebuild the system!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Rebuilding NixOS for $HOSTNAME"
|
2021-04-12 22:26:55 +02:00
|
|
|
system=$(nix-build -E "((import ${toString depot.path} {}).ops.nixos.findSystem \"$HOSTNAME\").system" --no-out-link --show-trace)
|
2020-07-03 06:26:33 +02:00
|
|
|
|
|
|
|
nix-env -p /nix/var/nix/profiles/system --set $system
|
|
|
|
$system/bin/switch-to-configuration switch
|
|
|
|
'';
|
2020-08-27 00:58:23 +02:00
|
|
|
|
|
|
|
# Systems that should be built in CI
|
2021-04-11 22:50:30 +02:00
|
|
|
whitbySystem = (nixosFor depot.ops.machines.whitby).system;
|
2020-08-31 02:36:03 +02:00
|
|
|
meta.targets = [ "whitbySystem" ];
|
2020-07-02 20:19:08 +02:00
|
|
|
}
|