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
|
|
|
|
inherit (depot.users.wpcarro.nixos) diogenes;
|
|
|
|
systemFor = sys: (depot.ops.nixos.nixosFor sys).system;
|
|
|
|
in
|
|
|
|
{
|
2021-12-16 00:40:44 +01:00
|
|
|
marcusSystem = systemFor depot.users.wpcarro.nixos.marcus;
|
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
|
|
|
|
|
|
|
|
# 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
|
|
|
|
readonly target="root@''${1}"
|
|
|
|
|
|
|
|
# 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-02-08 00:27:26 +01:00
|
|
|
meta.ci.targets = [ "marcusSystem" ];
|
2021-12-16 00:40:44 +01:00
|
|
|
}
|