Improve nix run .#HOSTNAME-nixos-rebuild

This commit is contained in:
Sandro - 2023-11-09 22:21:41 +01:00
parent e110b04549
commit 8ff2ad30f5
Signed by: sandro
1 changed files with 9 additions and 5 deletions

View File

@ -98,6 +98,7 @@ lib.attrsets.mapAttrs
hostConfig = self.nixosConfigurations."${name}".config;
hostPkgs = self.nixosConfigurations."${name}".pkgs;
declaredRunnerDrvPath = discardStringCtx hostConfig.microvm.declaredRunner.drvPath;
toplevelDrvPath = discardStringCtx;
toplevelOutPath = discardStringCtx;
# let /var/lib/microvm/*/flake point to the flake-update branch so that
# `microvm -u $NAME` updates to what hydra built today.
@ -117,11 +118,14 @@ lib.attrsets.mapAttrs
[[ $(ssh ${target} cat /etc/hostname) == ${name} ]]
nix copy --no-check-sigs --to ssh-ng://${target} ${inputPaths}
nix copy --no-check-sigs --derivation --to ssh-ng://${target} ${discardStringCtx}
nix copy --no-check-sigs --derivation --to ssh-ng://${target} ${toplevelDrvPath}
# use nixos-rebuild from target config
nixosRebuild=$(ssh ${target} nix build ${discardStringCtx} ${overrideInputsArgs} --no-link --json | ${lib.getExe hostPkgs.jq} -r '.[0].outputs.out')
ssh ${target} $nixosRebuild/bin/nixos-rebuild ${rebuildArg} "$@"
ssh ${target} bash -e <<END
nix build ${toplevelDrvPath}
nix-env -p /nix/var/nix/profiles/system --set ${toplevelOutPath}
${toplevelOutPath}/bin/switch-to-configuration "''${@:-switch}"
"${name}-nixos-rebuild-hydra" = pkgs.writeScriptBin "${name}-nixos-rebuild" ''
@ -190,13 +194,13 @@ lib.attrsets.mapAttrs
then ''
set -eou pipefail
${} ${inputPaths} ${declaredRunnerDrvPath}
${} ${declaredRunnerDrvPath}
${} NIXOS_REBUILD="''${NIXOS_REBUILD:-}" bash -e <<END
set -eou pipefail
${createDirsCopyCurrent name}
nix build -L --accept-flake-config -o current ${overrideInputsArgs} ${declaredRunnerDrvPath}
nix build -L --accept-flake-config -o current ${declaredRunnerDrvPath}
echo '${selfRef}' > flake
${createSymlinks name}