feat(wpcarro/diogenes): Support rebuild-diogenes
- deploy-diogenes: terraform updates + NixOS rebuilds - rebuild-diogenes: NixOS rebuilds Change-Id: Ibd6db7115d9919fa44ee9d318f88e1bf29e2bdce Reviewed-on: https://cl.tvl.fyi/c/depot/+/5160 Tested-by: BuildkiteCI Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com>
This commit is contained in:
parent
4f89dd3fdf
commit
8fb1ff3f25
4 changed files with 160 additions and 127 deletions
|
@ -12,6 +12,9 @@ case "${TARGET_TOOL}" in
|
||||||
deploy-diogenes)
|
deploy-diogenes)
|
||||||
attr="users.wpcarro.nixos.deploy-diogenes"
|
attr="users.wpcarro.nixos.deploy-diogenes"
|
||||||
;;
|
;;
|
||||||
|
rebuild-diogenes)
|
||||||
|
attr="users.wpcarro.nixos.rebuild-diogenes"
|
||||||
|
;;
|
||||||
import-gpg)
|
import-gpg)
|
||||||
attr="users.wpcarro.configs.import-gpg"
|
attr="users.wpcarro.configs.import-gpg"
|
||||||
;;
|
;;
|
||||||
|
|
1
users/wpcarro/bin/rebuild-diogenes
Symbolic link
1
users/wpcarro/bin/rebuild-diogenes
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
__dispatch.sh
|
|
@ -1,22 +1,48 @@
|
||||||
{ depot, pkgs, ... }:
|
{ depot, pkgs, ... }:
|
||||||
|
|
||||||
let systemFor = sys: (depot.ops.nixos.nixosFor sys).system;
|
let
|
||||||
in {
|
inherit (depot.users.wpcarro.nixos) diogenes;
|
||||||
|
systemFor = sys: (depot.ops.nixos.nixosFor sys).system;
|
||||||
|
in
|
||||||
|
{
|
||||||
marcusSystem = systemFor depot.users.wpcarro.nixos.marcus;
|
marcusSystem = systemFor depot.users.wpcarro.nixos.marcus;
|
||||||
|
|
||||||
|
# Apply terraform updates and rebuild NixOS for diogenes.
|
||||||
deploy-diogenes = pkgs.writeShellScriptBin "deploy-diogenes" ''
|
deploy-diogenes = pkgs.writeShellScriptBin "deploy-diogenes" ''
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
readonly TF_STATE_DIR=/depot/users/wpcarro/terraform
|
readonly TF_STATE_DIR=/depot/users/wpcarro/terraform
|
||||||
rm -f $TF_STATE_DIR/*.json
|
rm -f $TF_STATE_DIR/*.json
|
||||||
readonly STORE_PATH="$(nix-build /depot -A users.wpcarro.nixos.diogenes)"
|
readonly STORE_PATH="${diogenes.json}"
|
||||||
|
# We can't use the result symlink because terraform looks for a *.json file
|
||||||
|
# in the current working directory.
|
||||||
cp $STORE_PATH $TF_STATE_DIR
|
cp $STORE_PATH $TF_STATE_DIR
|
||||||
|
|
||||||
function cleanup() {
|
if [ ! -d $TF_STATE_DIR/.terraform ]; then
|
||||||
rm -f "$TF_STATE_DIR/$(basename $STORE_PATH)"
|
${pkgs.terraform}/bin/terraform -chdir="$TF_STATE_DIR" init
|
||||||
}
|
fi
|
||||||
|
|
||||||
|
# function cleanup() {
|
||||||
|
# rm -f "$TF_STATE_DIR/$(basename $STORE_PATH)"
|
||||||
|
# }
|
||||||
|
# trap cleanup EXIT
|
||||||
|
|
||||||
trap cleanup EXIT
|
|
||||||
${pkgs.terraform}/bin/terraform -chdir="$TF_STATE_DIR" apply
|
${pkgs.terraform}/bin/terraform -chdir="$TF_STATE_DIR" apply
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
# 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'
|
||||||
|
'';
|
||||||
|
|
||||||
meta.ci.targets = [ "marcusSystem" ];
|
meta.ci.targets = [ "marcusSystem" ];
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,9 @@ in
|
||||||
osPath = unsafeDiscardStringContext (toString osRoot.outPath);
|
osPath = unsafeDiscardStringContext (toString osRoot.outPath);
|
||||||
drvPath = unsafeDiscardStringContext (toString osRoot.drvPath);
|
drvPath = unsafeDiscardStringContext (toString osRoot.drvPath);
|
||||||
in
|
in
|
||||||
writeText "terraform.tf.json" (toJSON (lib.recursiveUpdate extraConfig {
|
{
|
||||||
|
inherit drvPath osPath;
|
||||||
|
json = writeText "terraform.tf.json" (toJSON (lib.recursiveUpdate extraConfig {
|
||||||
provider.google = {
|
provider.google = {
|
||||||
inherit project region zone;
|
inherit project region zone;
|
||||||
};
|
};
|
||||||
|
@ -186,4 +188,5 @@ in
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue