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
GPG Key ID: 3AF5A43A3EECC2E5
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 hostConfig.system.build.toplevel.drvPath;
toplevelOutPath = discardStringCtx hostConfig.system.build.toplevel.outPath;
# 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 hostConfig.system.build.nixos-rebuild.drvPath}
nix copy --no-check-sigs --derivation --to ssh-ng://${target} ${toplevelDrvPath}
# use nixos-rebuild from target config
nixosRebuild=$(ssh ${target} nix build ${discardStringCtx hostConfig.system.build.nixos-rebuild.drvPath} ${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}"
END
'';
"${name}-nixos-rebuild-hydra" = pkgs.writeScriptBin "${name}-nixos-rebuild" ''
@ -190,13 +194,13 @@ lib.attrsets.mapAttrs
then ''
set -eou pipefail
${hostConfig.system.build.copyToServer} ${inputPaths} ${declaredRunnerDrvPath}
${hostConfig.system.build.copyToServer} ${declaredRunnerDrvPath}
${hostConfig.system.build.runOnServer} 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}