This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

tools.deploy: show closure changes with nvd, file summary before source diff

+38 -5
+38 -5
tools/deploy/flake-module.nix
··· 117 117 EOF 118 118 } 119 119 120 + # source_diff: per-file +/- summary, then the full diff, of the 121 + # running system's source against the incoming one. 122 + source_diff() { 123 + ssh "''${ssh_opts[@]}" "$target" bash -s -- "$state" <<'EOF' 124 + old=$1/src new=$1/incoming 125 + if [ ! -d "$old" ]; then 126 + echo "no source recorded for the running system" 127 + exit 0 128 + fi 129 + # diff exits 1 when the trees differ, 2 on trouble. 130 + d() { diff -ruN "$@" "$old" "$new" || [ $? -eq 1 ]; } 131 + d | awk -v pre="$new/" ' 132 + /^diff -ruN / { 133 + f = substr($0, index($0, " " pre) + 1 + length(pre)) 134 + files[++n] = f; hdr = 2; next 135 + } 136 + hdr > 0 { hdr--; next } 137 + /^\+/ { add[f]++ } 138 + /^-/ { del[f]++ } 139 + END { 140 + if (n == 0) { print "no source changes"; exit } 141 + for (i = 1; i <= n; i++) { 142 + f = files[i] 143 + printf " %-60s \033[32m+%d\033[0m \033[31m-%d\033[0m\n", f, add[f], del[f] 144 + } 145 + printf "%d files changed\n\n", n 146 + }' 147 + d --color=always 148 + EOF 149 + } 150 + 120 151 step "connecting to $target" 121 152 # shellcheck disable=SC2016 # expanded on the target 122 153 remote 'test -e /etc/NIXOS && command -v systemd-run >/dev/null' || ··· 153 184 "rm -rf $state/incoming && mv $state/incoming.new $state/incoming" 154 185 155 186 step "source changes" 156 - # shellcheck disable=SC2016 # expanded on the target 157 - remote "if [ -d $state/src ]; then diff -ruN --color=always $state/src $state/incoming" \ 158 - '|| [ $? -eq 1 ]; else echo "no source recorded for the running system"; fi' | page 187 + source_diff | page 159 188 160 189 step "building $machine on $target" 190 + # nvd comes from the machine's own nixpkgs, so it is built for 191 + # the target and usually substituted; out-links are result 192 + # (system) and result-1 (nvd), in installable order. 161 193 start deploy-build \ 162 194 /run/current-system/sw/bin/nix --extra-experimental-features "nix-command flakes" \ 163 195 --log-format internal-json -v build --out-link "$state/result" \ 164 - "$state/incoming#nixosConfigurations.$machine.config.system.build.toplevel" 196 + "$state/incoming#nixosConfigurations.$machine.config.system.build.toplevel" \ 197 + "$state/incoming#nixosConfigurations.$machine.pkgs.nvd" 165 198 fi 166 199 follow deploy-build | nom --json 167 200 system=$(remote readlink -f "$state/result") ··· 170 203 if [ "$(remote readlink -f /run/current-system)" = "$system" ]; then 171 204 echo "$system is already running" 172 205 else 173 - remote "$nix store diff-closures /run/current-system $system" 206 + remote "$state/result-1/bin/nvd diff /run/current-system $system" 174 207 fi 175 208 176 209 read -r -p "switch $target to $system? [y/N] " answer </dev/tty