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;
|
2022-05-29 11:06:14 +02:00
|
|
|
nix.nixPath =
|
|
|
|
let
|
|
|
|
# Due to nixpkgsBisectPath, pkgs.path is not always in the nix store
|
|
|
|
nixpkgsStorePath =
|
|
|
|
if lib.hasPrefix builtins.storeDir (toString pkgs.path)
|
|
|
|
then builtins.storePath pkgs.path # nixpkgs is already in the store
|
|
|
|
else pkgs.path; # we need to dump nixpkgs to the store either way
|
|
|
|
in
|
|
|
|
[
|
|
|
|
("nixos=" + nixpkgsStorePath)
|
|
|
|
("nixpkgs=" + nixpkgsStorePath)
|
|
|
|
];
|
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
|
|
|
|
2024-02-20 19:14:51 +01:00
|
|
|
rebuild-system = rebuildSystemWith (
|
|
|
|
# HACK: use the string of the original source to avoid copying the whole
|
|
|
|
# depot into the store just for this
|
|
|
|
builtins.toString depot.path.origSrc);
|
2021-12-17 01:49:23 +01:00
|
|
|
|
|
|
|
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;
|
2023-09-22 18:51:35 +02:00
|
|
|
nixeryDev01System = (nixosFor depot.ops.machines.nixery-01).system;
|
|
|
|
meta.ci.targets = [ "sandunySystem" "whitbySystem" "nixeryDev01System" ];
|
2020-07-02 20:19:08 +02:00
|
|
|
}
|