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 = { ... }: {
|
2021-04-19 23:58:11 +02:00
|
|
|
# Ensure that pkgs == third_party.nix
|
|
|
|
nixpkgs.pkgs = depot.third_party.nixpkgs;
|
|
|
|
nix.nixPath = [
|
|
|
|
"nixos=${pkgs.path}"
|
2021-05-21 01:03:54 +02:00
|
|
|
"nixpkgs=${pkgs.path}"
|
2021-04-19 23:58:11 +02:00
|
|
|
];
|
2021-04-02 14:13:08 +02:00
|
|
|
};
|
|
|
|
|
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-05-24 23:29:44 +02:00
|
|
|
|
|
|
|
specialArgs = {
|
|
|
|
inherit (args) depot;
|
|
|
|
};
|
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
|
|
|
|
2021-12-17 01:49:23 +01:00
|
|
|
rebuild-system = rebuildSystemWith depot.path;
|
|
|
|
|
|
|
|
rebuildSystemWith = depotPath: pkgs.writeShellScriptBin "rebuild-system" ''
|
2020-07-03 06:26:33 +02:00
|
|
|
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-12-17 01:49:23 +01:00
|
|
|
system=$(${pkgs.nix}/bin/nix-build -E "((import ${depotPath} {}).ops.nixos.findSystem \"$HOSTNAME\").system" --no-out-link --show-trace)
|
2020-07-03 06:26:33 +02:00
|
|
|
|
2021-12-17 01:49:23 +01:00
|
|
|
${pkgs.nix}/bin/nix-env -p /nix/var/nix/profiles/system --set $system
|
2020-07-03 06:26:33 +02:00
|
|
|
$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;
|
2022-02-17 00:02:14 +01:00
|
|
|
sandunySystem = (nixosFor depot.ops.machines.sanduny).system;
|
2022-05-04 17:56:50 +02:00
|
|
|
meta.ci.targets = [ "sandunySystem" "whitbySystem" ];
|
2020-07-02 20:19:08 +02:00
|
|
|
}
|