2021-12-30 20:25:03 +01:00
|
|
|
{ depot, pkgs, ... }:
|
2021-12-16 00:40:44 +01:00
|
|
|
|
2022-02-01 22:34:49 +01:00
|
|
|
let
|
2022-05-23 05:19:27 +02:00
|
|
|
inherit (depot.users.wpcarro.nixos)
|
|
|
|
ava
|
|
|
|
diogenes
|
|
|
|
marcus
|
|
|
|
tarasco;
|
|
|
|
|
2022-02-01 22:34:49 +01:00
|
|
|
systemFor = sys: (depot.ops.nixos.nixosFor sys).system;
|
|
|
|
in
|
|
|
|
{
|
2022-05-23 05:19:27 +02:00
|
|
|
avaSystem = systemFor ava;
|
|
|
|
marcusSystem = systemFor marcus;
|
|
|
|
tarascoSystem = systemFor ava;
|
2022-02-01 22:34:49 +01:00
|
|
|
|
|
|
|
# Apply terraform updates and rebuild NixOS for diogenes.
|
2021-12-30 20:25:03 +01:00
|
|
|
deploy-diogenes = pkgs.writeShellScriptBin "deploy-diogenes" ''
|
|
|
|
set -euo pipefail
|
|
|
|
readonly TF_STATE_DIR=/depot/users/wpcarro/terraform
|
|
|
|
rm -f $TF_STATE_DIR/*.json
|
2022-02-01 22:34:49 +01:00
|
|
|
readonly STORE_PATH="${diogenes.json}"
|
|
|
|
# We can't use the result symlink because terraform looks for a *.json file
|
|
|
|
# in the current working directory.
|
2021-12-30 20:25:03 +01:00
|
|
|
cp $STORE_PATH $TF_STATE_DIR
|
|
|
|
|
2022-02-01 22:34:49 +01:00
|
|
|
if [ ! -d $TF_STATE_DIR/.terraform ]; then
|
|
|
|
${pkgs.terraform}/bin/terraform -chdir="$TF_STATE_DIR" init
|
|
|
|
fi
|
|
|
|
|
2022-02-14 23:22:55 +01:00
|
|
|
function cleanup() {
|
|
|
|
rm -f "$TF_STATE_DIR/$(basename $STORE_PATH)"
|
|
|
|
}
|
|
|
|
trap cleanup EXIT
|
2021-12-30 20:25:03 +01:00
|
|
|
|
|
|
|
${pkgs.terraform}/bin/terraform -chdir="$TF_STATE_DIR" apply
|
|
|
|
'';
|
2021-12-17 00:29:59 +01:00
|
|
|
|
2022-02-01 22:34:49 +01:00
|
|
|
# Rebuild NixOS for diogenes without applying terraform updates.
|
|
|
|
rebuild-diogenes = pkgs.writeShellScriptBin "rebuild-diogenes" ''
|
|
|
|
set -euo pipefail
|
2022-02-14 23:24:03 +01:00
|
|
|
readonly target="root@billandhiscomputer.com"
|
2022-02-01 22:34:49 +01:00
|
|
|
|
|
|
|
# We need to call nix-build here on the drvPath because it may not be in
|
|
|
|
# /nix/store yet.
|
|
|
|
readonly STORE_PATH="$(nix-build ${diogenes.drvPath} --no-out-link --show-trace)"
|
|
|
|
nix-copy-closure --to $target ${diogenes.osPath} \
|
|
|
|
--gzip --use-substitutes $STORE_PATH
|
|
|
|
|
|
|
|
ssh $target 'nix-env --profile /nix/var/nix/profiles/system --set ${diogenes.osPath}'
|
|
|
|
ssh $target '${diogenes.osPath}/bin/switch-to-configuration switch'
|
|
|
|
'';
|
|
|
|
|
2022-04-13 04:08:31 +02:00
|
|
|
meta.ci.targets = [
|
|
|
|
"avaSystem"
|
|
|
|
"marcusSystem"
|
2022-05-23 05:19:27 +02:00
|
|
|
"tarascoSystem"
|
2022-04-13 04:08:31 +02:00
|
|
|
];
|
2021-12-16 00:40:44 +01:00
|
|
|
}
|