Justfile: implement update-remote-device

This bumps the versions for the remote device, attempts a rebuild and
commits the resulting versions if the rebuild succeeded.
This commit is contained in:
steveej 2019-03-06 13:52:23 +01:00
parent 5f2f499471
commit 2c9da1f12e
2 changed files with 47 additions and 4 deletions

View file

@ -1,3 +1,6 @@
_DEFAULT_VERSION_TMPL:
echo "{{invocation_directory()}}/nix/variables/versions.tmpl.nix"
_usage:
just -l
@ -21,10 +24,10 @@ _rebuild-device dir rebuildarg="dry-activate" +moreargs="": _render_templates
set -ex
just -v _device rebuild {{dir}} --argstr rebuildarg {{rebuildarg}} {{moreargs}}
rebuild-remote-device dir target rebuildarg="dry-activate" :
rebuild-remote-device device target rebuildarg="dry-activate" :
#!/usr/bin/env bash
set -ex
just -v _rebuild-device {{dir}} {{rebuildarg}} --argstr moreargs "'--target-host\ {{target}}'"
just -v _rebuild-device nix/os/devices/{{device}} {{rebuildarg}} --argstr moreargs "'--target-host\ {{target}}'"
# Rebuild this device's NixOS
rebuild-this-device rebuildarg="dry-activate":
@ -66,9 +69,34 @@ rebuild-this-device rebuildarg="dry-activate":
fi
fi
# This could be used to inject another channel
# --argstr moreargs "\'-I nixos-unstable=https://nixos.org/channels/nixos-unstable/nixexprs.tar.xz\'"
update-remote-device device target rebuildmode='switch':
#!/usr/bin/env bash
set -e
template=nix/os/devices/{{device}}/versions.tmpl.nix
outfile=nix/os/devices/{{device}}/versions.nix
if ! test -e ${template}; then
template="$(just _DEFAULT_VERSION_TMPL)"
fi
esh -o ${outfile} ${template}
if ! test "$(git diff ${outfile})"; then
echo Already on latest versions
exit 0
fi
just -v rebuild-remote-device {{device}} {{target}} dry-activate || {
echo ERROR: rebuild in mode 'dry-active' failed after updating ${outfile}
exit 1
}
just -v rebuild-remote-device {{ device }} {{ target }} {{ rebuildmode }} || {
echo ERROR: rebuild in mode '{{ rebuildmode }}' failed after updating ${outfile}
exit 1
}
git commit -v ${outfile} -m "nix/os/devices/{{ device }}: bump versions"
# Update the channel versions and (by default) switch to new environment
update-this-device rebuild-mode='switch':