diff --git a/Justfile b/Justfile index f3ff469..5b66483 100755 --- a/Justfile +++ b/Justfile @@ -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': diff --git a/nix/variables/versions.tmpl.nix b/nix/variables/versions.tmpl.nix new file mode 100644 index 0000000..93b44b8 --- /dev/null +++ b/nix/variables/versions.tmpl.nix @@ -0,0 +1,15 @@ +{ + channelsNixosStable = { + ref = "nixos-19.03"; + rev = "<% git ls-remote https://github.com/nixos/nixpkgs-channels nixos-19.03 | awk '{ print $1 }' | tr -d '\n' -%>"; + }; + channelsNixosUnstable = { + ref = "nixos-unstable"; + rev = "<% git ls-remote https://github.com/nixos/nixpkgs-channels nixos-unstable | awk '{ print $1 }' | tr -d '\n' -%>"; + }; + homeManagerModule = { + url = "https://github.com/rycee/home-manager"; + ref = "master"; + rev = "<% git ls-remote https://github.com/rycee/home-manager.git master | awk '{ print $1 }' | tr -d '\n' -%>"; + }; +}