This commit is contained in:
Peder Bergebakken Sundt 2025-03-21 19:22:53 +01:00
parent dcbf828bc4
commit 8bef723284
2 changed files with 41 additions and 26 deletions

@ -54,6 +54,7 @@
environment.systemPackages = [
pkgs.cemu
pkgs.superTuxKart
];

@ -1,3 +1,5 @@
set positional-arguments # makes variables accesible as $1 $2 $@
export invokedir := invocation_directory()
export GUM_CHOOSE_HEIGHT := "15"
export GUM_FILTER_HEIGHT := "15"
@ -32,16 +34,18 @@ update:
@update-select:
git reset flake.lock
git restore flake.lock
nix eval .#inputs --apply builtins.attrNames --json 2>/dev/null \
nix eval --file flake.nix --apply 'x: builtins.attrNames x.inputs' --json \
| (printf "%s\n" --commit-lock-file; jq '.[]' -r | tr '0123456789' '9876543210' | sort | tr '0123456789' '9876543210' | grep -v "^self$") \
| gum choose --no-limit \
| xargs nix flake update
git add flake.lock
# todo: support system-manager
#build hostname=`if test -z "${IS_REMOTE_ENV:-}"; then just _a_host_timeout; else printf "\n"; fi`:
build hostname="":
nixos-rebuild build --accept-flake-config --show-trace --flake .#"{{hostname}}"
# todo: support system-manager
#build-no-remote-builders hostname=`if test -z "$IS_REMOTE_ENV"; then just _a_host_timeout; else printf "\n"; fi`:
build-no-remote-builders hostname="":
nixos-rebuild build --accept-flake-config --show-trace --flake .#"{{hostname}}" --builders ""
@ -78,31 +82,36 @@ inspect:
inspect-config host=`just _a_host` prefix="":
nix run -- nixpkgs#nix-inspect -e '(builtins.getFlake "'"$PWD"'").nixosConfigurations."{{host}}".config{{ if prefix == "" { "" } else { "." + prefix } }}'
@_a_host:
hostnames="$(nix eval .#nixosConfigurations --apply builtins.attrNames --json 2>/dev/null | jq '.[]' -r)"; \
if test "$(grep <<<"$hostnames" "^$(just remote-current)$" | wc -l)" -eq 1; then hostnames="$(just remote-current; grep <<<"$hostnames" -v "^$(just remote-current)$")"; fi; \
if test "$(grep <<<"$hostnames" "^$(hostname)$" | wc -l)" -eq 1; then hostnames="$(hostname; grep <<<"$hostnames" -v "^$(hostname)$")"; fi; \
_a_host:
#!/usr/bin/env -S bash -euo pipefail
hostnames="$(nix eval .#nixosConfigurations --apply builtins.attrNames --json 2>/dev/null | jq '.[]' -r)"
if test "$(grep <<<"$hostnames" "^$(just remote-current)$" | wc -l)" -eq 1; then hostnames="$(just remote-current; grep <<<"$hostnames" -v "^$(just remote-current)$")"; fi
if test "$(grep <<<"$hostnames" "^$(hostname)$" | wc -l)" -eq 1; then hostnames="$(hostname; grep <<<"$hostnames" -v "^$(hostname)$")"; fi
gum <<<"$hostnames" filter --placeholder "Pick a host..."
# ctrl-c is counted as a timeout...
@_a_host_timeout:
hostnames="$(nix eval .#nixosConfigurations --apply builtins.attrNames --json 2>/dev/null | jq '.[]' -r)"; \
if test "$(grep <<<"$hostnames" "^$(hostname)$" | wc -l)" -eq 1; then hostnames="$(hostname; grep <<<"$hostnames" -v "^$(hostname)$")"; fi; \
_a_host_timeout:
#!/usr/bin/env -S bash -euo pipefail
hostnames="$(nix eval .#nixosConfigurations --apply builtins.attrNames --json 2>/dev/null | jq '.[]' -r)"
if test "$(grep <<<"$hostnames" "^$(hostname)$" | wc -l)" -eq 1; then hostnames="$(hostname; grep <<<"$hostnames" -v "^$(hostname)$")"; fi
gum <<<"$hostnames" filter --placeholder "Pick a host..." --timeout 5s || hostname
@_some_hosts:
hostnames="$(nix eval .#nixosConfigurations --apply builtins.attrNames --json 2>/dev/null | jq '.[]' -r)"; \
if test "$(grep <<<"$hostnames" "^$(hostname)$" | wc -l)" -eq 1; then hostnames="$(hostname; grep <<<"$hostnames" -v "^$(hostname)$")"; fi; \
_some_hosts:
#!/usr/bin/env -S bash -euo pipefail
hostnames="$(nix eval .#nixosConfigurations --apply builtins.attrNames --json 2>/dev/null | jq '.[]' -r)"
if test "$(grep <<<"$hostnames" "^$(hostname)$" | wc -l)" -eq 1; then hostnames="$(hostname; grep <<<"$hostnames" -v "^$(hostname)$")"; fi
gum <<<"$hostnames" filter --placeholder "Pick a host..." --no-limit
@_a_fqdn:
hostnames="$(nix eval .#nixosConfigurations --apply 'c: builtins.attrValues (builtins.mapAttrs (_: x: x.config.networking.fqdn) c)' --json 2>/dev/null | jq '.[]' -r)"; \
if test "$(grep <<<"$hostnames" "^$(hostname --fqdn)$" | wc -l)" -eq 1; then hostnames="$(hostname --fqdn; grep <<<"$hostnames" -v "^$(hostname --fqdn)$")"; fi; \
_a_fqdn:
#!/usr/bin/env -S bash -euo pipefail
hostnames="$(nix eval .#nixosConfigurations --apply 'c: builtins.attrValues (builtins.mapAttrs (_: x: x.config.networking.fqdn) c)' --json 2>/dev/null | jq '.[]' -r)"
if test "$(grep <<<"$hostnames" "^$(hostname --fqdn)$" | wc -l)" -eq 1; then hostnames="$(hostname --fqdn; grep <<<"$hostnames" -v "^$(hostname --fqdn)$")"; fi
gum <<<"$hostnames" filter --placeholder "Pick a host..."
@_some_fqdns:
hostnames="$(nix eval .#nixosConfigurations --apply 'c: builtins.attrValues (builtins.mapAttrs (_: x: x.config.networking.fqdn) c)' --json 2>/dev/null | jq '.[]' -r)"; \
if test "$(grep <<<"$hostnames" "^$(hostname --fqdn)$" | wc -l)" -eq 1; then hostnames="$(hostname --fqdn; grep <<<"$hostnames" -v "^$(hostname --fqdn)$")"; fi; \
_some_fqdns:
#!/usr/bin/env -S bash -euo pipefail
hostnames="$(nix eval .#nixosConfigurations --apply 'c: builtins.attrValues (builtins.mapAttrs (_: x: x.config.networking.fqdn) c)' --json 2>/dev/null | jq '.[]' -r)"
if test "$(grep <<<"$hostnames" "^$(hostname --fqdn)$" | wc -l)" -eq 1; then hostnames="$(hostname --fqdn; grep <<<"$hostnames" -v "^$(hostname --fqdn)$")"; fi
gum <<<"$hostnames" filter --placeholder "Pick a host..." --no-limit
@remote-current:
@ -116,13 +125,14 @@ inspect-config host=`just _a_host` prefix="":
@remote-set remote=`just remote-current >&2 && just _a_remote_label`:
remote-set "{{remote}}"
@motd:
motd:
#!/usr/bin/env -S bash -euo pipefail
printf "%s\n" "Current remote: $(just remote-current)"
just remote-list
printf "\n"; \
todos=$(rg 'TODO' | wc -l); \
if [[ "$todos" -gt 10 ]]; then \
printf "%s\n" "There are $todos 'TODO's"; \
printf "\n"
todos=$(rg 'TODO' | wc -l)
if [[ "$todos" -gt 10 ]]; then
printf "%s\n" "There are $todos 'TODO's"
fi
@_a_remote_label:
@ -137,10 +147,14 @@ inspect-config host=`just _a_host` prefix="":
@_some_remote_fqdns:
just remote-list | gum filter --placeholder "Pick remote..." --no-limit | cut -d' ' -f5-
@_remote_ensure hostname=`just _a_fqdn`:
if test ! -s .remote.toml; then remote-init "{{ hostname }}"; \
elif tomlq <.remote.toml '.hosts | to_entries[] |.value.host' -r | grep -q "{{ hostname }}"; then true; \
else remote-add "{{ hostname }}"; \
_remote_ensure $hostname=`just _a_fqdn`:
#!/usr/bin/env -S bash -euo pipefail
if test ! -s .remote.toml; then
remote-init "$hostname"
elif tomlq <.remote.toml '.hosts | to_entries[] |.value.host' -r | grep -q "$hostname"; then
true
else
remote-add "$hostname"
fi
@_remote_label_from_fqdn hostname=`just _a_fqdn`: