From 4e44da29b58f8f34da73cfbabd5ef75f3028ff41 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Fri, 30 May 2025 19:10:14 +0200 Subject: [PATCH 1/6] justfil: _a_machine: remember last choice --- justfile | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/justfile b/justfile index 633263c..8afb7e6 100644 --- a/justfile +++ b/justfile @@ -21,5 +21,23 @@ run-vm machine=`just _a_machine`: | xargs -L 1 nix flake lock --update-input + +# helpers + +[no-exit-message] _a_machine: - nix eval .#nixosConfigurations --apply builtins.attrNames --json | jq .[] -r | gum filter + #!/usr/bin/env -S sh -euo pipefail + machines="$( + nix eval {{nix_eval_opts}} .#nixosConfigurations --apply builtins.attrNames --json | jq .[] -r + )" + [ -n "$machines" ] || { echo >&2 "ERROR: no machines found"; false; } + if [ -s .direnv/vars/last-machine.txt ]; then + machines="$( + grep <<<"$machines" -xF "$(cat .direnv/vars/last-machine.txt)" ||: + grep <<<"$machines" -xFv "$(cat .direnv/vars/last-machine.txt)" ||: + )" + fi + choice="$(gum filter <<<"$machines")" + mkdir -p .direnv/vars + cat <<<"$choice" >.direnv/vars/last-machine.txt + cat <<<"$choice" From dca686204566d2e7871188ca87f0867aaf2e69cf Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Fri, 30 May 2025 19:13:06 +0200 Subject: [PATCH 2/6] justfile: silence 'nix eval' spam --- justfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/justfile b/justfile index 8afb7e6..0486f1e 100644 --- a/justfile +++ b/justfile @@ -1,5 +1,6 @@ export GUM_FILTER_HEIGHT := "15" nom := `if command -v nom >/dev/null; then echo nom; else echo nix; fi` +nix_eval_opts := "--log-format raw --option warn-dirty false" @_default: just "$(gum choose --ordered --header "Pick a recipie..." $(just --summary --unsorted))" @@ -15,7 +16,7 @@ run-vm machine=`just _a_machine`: QEMU_NET_OPTS="hostfwd=tcp::8080-:80,hostfwd=tcp::8081-:443,hostfwd=tcp::2222-:22" ./result/bin/run-*-vm @update-inputs: - nix eval .#inputs --apply builtins.attrNames --json \ + nix eval {{nix_eval_opts}} .#inputs --apply builtins.attrNames --json \ | jq '.[]' -r \ | gum choose --no-limit --height=15 \ | xargs -L 1 nix flake lock --update-input From b40cde891e2a8d9f904b57572f6475062f9da5cd Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Fri, 30 May 2025 19:14:30 +0200 Subject: [PATCH 3/6] justfile: passthru extra args with 'set positional-arguments' --- justfile | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/justfile b/justfile index 0486f1e..58cd357 100644 --- a/justfile +++ b/justfile @@ -1,3 +1,4 @@ +set positional-arguments # makes variables accesible as $1 $2 $@ export GUM_FILTER_HEIGHT := "15" nom := `if command -v nom >/dev/null; then echo nom; else echo nix; fi` nix_eval_opts := "--log-format raw --option warn-dirty false" @@ -5,21 +6,21 @@ nix_eval_opts := "--log-format raw --option warn-dirty false" @_default: just "$(gum choose --ordered --header "Pick a recipie..." $(just --summary --unsorted))" -check: - nix flake check --keep-going +check *_: + nix flake check --keep-going "$@" -build-machine machine=`just _a_machine`: - {{nom}} build .#nixosConfigurations.{{ machine }}.config.system.build.toplevel +build-machine machine=`just _a_machine` *_: + {{nom}} build .#nixosConfigurations.{{ machine }}.config.system.build.toplevel "${@:2}" -run-vm machine=`just _a_machine`: - nixos-rebuild build-vm --flake .#{{ machine }} +run-vm machine=`just _a_machine` *_: + nixos-rebuild build-vm --flake .#{{ machine }} "${@:2}" QEMU_NET_OPTS="hostfwd=tcp::8080-:80,hostfwd=tcp::8081-:443,hostfwd=tcp::2222-:22" ./result/bin/run-*-vm -@update-inputs: +@update-inputs *_: nix eval {{nix_eval_opts}} .#inputs --apply builtins.attrNames --json \ | jq '.[]' -r \ | gum choose --no-limit --height=15 \ - | xargs -L 1 nix flake lock --update-input + | xargs -L 1 nix flake lock --update-input "$@" From 3e156a8649042d1f19c20db989e5bafe7e3be876 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Fri, 30 May 2025 19:14:55 +0200 Subject: [PATCH 4/6] justfile: only use nom if stdout is a tty --- justfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/justfile b/justfile index 58cd357..d9dbebd 100644 --- a/justfile +++ b/justfile @@ -1,6 +1,6 @@ set positional-arguments # makes variables accesible as $1 $2 $@ export GUM_FILTER_HEIGHT := "15" -nom := `if command -v nom >/dev/null; then echo nom; else echo nix; fi` +nom := `if [[ -t 1 ]] && command -v nom >/dev/null; then echo nom; else echo nix; fi` nix_eval_opts := "--log-format raw --option warn-dirty false" @_default: From e5b38cd2c117b47bfbf7964f0627d55ae1de0d11 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Fri, 30 May 2025 19:15:48 +0200 Subject: [PATCH 5/6] justfile: add repl, eval and eval-vm --- justfile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/justfile b/justfile index d9dbebd..93aefea 100644 --- a/justfile +++ b/justfile @@ -22,6 +22,14 @@ run-vm machine=`just _a_machine` *_: | gum choose --no-limit --height=15 \ | xargs -L 1 nix flake lock --update-input "$@" +@repl $machine=`just _a_machine` *_: + set -v; nixos-rebuild --flake .#"$machine" repl "${@:2}" + +@eval $machine=`just _a_machine` $attrpath="system.build.toplevel.outPath" *_: + set -v; nix eval {{nix_eval_opts}} ".#nixosConfigurations.\"$machine\".config.$attrpath" --show-trace "${@:3}" + +@eval-vm $machine=`just _a_machine` $attrpath="system.build.toplevel.outPath" *_: + just eval "$machine" "virtualisation.vmVariant.$attrpath" "${@:3}" # helpers From 4ab133e541054b7bbbf90d51b8a32833a020d296 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Fri, 30 May 2025 19:16:26 +0200 Subject: [PATCH 6/6] justfile: update 'update-inputs' to changed nix3 cli, make more robust to dirty tree --- justfile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/justfile b/justfile index 93aefea..31aa607 100644 --- a/justfile +++ b/justfile @@ -17,10 +17,13 @@ run-vm machine=`just _a_machine` *_: QEMU_NET_OPTS="hostfwd=tcp::8080-:80,hostfwd=tcp::8081-:443,hostfwd=tcp::2222-:22" ./result/bin/run-*-vm @update-inputs *_: - nix eval {{nix_eval_opts}} .#inputs --apply builtins.attrNames --json \ - | jq '.[]' -r \ - | gum choose --no-limit --height=15 \ - | xargs -L 1 nix flake lock --update-input "$@" + @git reset flake.lock + @git restore flake.lock + nix eval {{nix_eval_opts}} --file flake.nix --apply 'x: builtins.attrNames x.inputs' --json \ + | { printf "%s\n" --commit-lock-file; jq '.[]' -r | grep -vxF "self" ||:; } \ + | gum choose --no-limit --header "Choose extra arguments:" \ + | tee >(xargs -d'\n' echo + nix flake update "$@" >&2) \ + | xargs -d'\n' nix flake update "$@" @repl $machine=`just _a_machine` *_: set -v; nixos-rebuild --flake .#"$machine" repl "${@:2}"