add mprocs remote runner

This commit is contained in:
Peder Bergebakken Sundt 2024-09-15 22:02:35 +02:00
parent 64dbfdc3cf
commit d125eec709
4 changed files with 36 additions and 9 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ result
.remote.toml .remote.toml
_* _*
/logs /logs
mprocs.log

View File

@ -1,5 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
export HOST_SHELL="$(command -v "$SHELL")" export HOST_SHELL="$(command -v "$SHELL")"
export IS_REMOTE_ENV=1
eval "$(nix print-dev-env .#remoteenv)" eval "$(nix print-dev-env .#remoteenv)"
echo Entered "$(hostname --fqdn)" echo Entered "$(hostname --fqdn)"
df -h /nix/store df -h /nix/store

View File

@ -321,9 +321,9 @@
# TODO: get faketty to work ${expect}/bin/unbuffer is bad # TODO: get faketty to work ${expect}/bin/unbuffer is bad
nixos-rebuild-nom = pkgs.writeScriptBin "nixos-rebuild" '' nixos-rebuild-nom = pkgs.writeScriptBin "nixos-rebuild" ''
if test -t 1 && test -z "''${NIX_NO_NOM-}"; then if test -t 1 && test -z "''${NIX_NO_NOM-}"; then
exec ${lib.getExe pkgs.nixos-rebuild} "$@" -L |& ${lib.getExe pkgs.nix-output-monitor} exec ${lib.getExe pkgs.nixos-rebuild} -L "$@" |& ${lib.getExe pkgs.nix-output-monitor}
else else
exec ${lib.getExe pkgs.nixos-rebuild} "$@" -L exec ${lib.getExe pkgs.nixos-rebuild} -L "$@"
fi fi
''; '';
@ -383,6 +383,7 @@
pkgs.ssh-to-age pkgs.ssh-to-age
pkgs.just pkgs.just
pkgs.gum pkgs.gum
pkgs.mprocs
]; ];
in { in {
envrc-local = mkShell envrc-pkgs; envrc-local = mkShell envrc-pkgs;

View File

@ -28,9 +28,12 @@ update:
| gum choose --no-limit --height=15 \ | gum choose --no-limit --height=15 \
| xargs nix flake update --commit-lock-file | xargs nix flake update --commit-lock-file
build hostname=`just _a_host`: build hostname=`if test -z "$IS_REMOTE_ENV"; then just _a_host; else echo; fi`:
nixos-rebuild build --accept-flake-config --show-trace --flake .#"{{hostname}}" nixos-rebuild build --accept-flake-config --show-trace --flake .#"{{hostname}}"
build-no-remote-builders hostname=`if test -z "$IS_REMOTE_ENV"; then just _a_host; else echo; fi`:
nixos-rebuild build --accept-flake-config --show-trace --flake .#"{{hostname}}" --builders ""
build-vm hostname=`just _a_host`: build-vm hostname=`just _a_host`:
nixos-rebuild build-vm --accept-flake-config --show-trace --flake .#"{{hostname}}" nixos-rebuild build-vm --accept-flake-config --show-trace --flake .#"{{hostname}}"
@ -64,26 +67,42 @@ inspect-config host=`just _a_host`:
if test "$(grep <<<"$hostnames" "^$(hostname)$" | wc -l)" -eq 1; then hostnames="$(hostname; grep <<<"$hostnames" -v "^$(hostname)$")"; 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..." gum <<<"$hostnames" filter --placeholder "Pick a host..."
@_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; \
gum <<<"$hostnames" filter --placeholder "Pick a host..." --no-limit
@_a_fqdn: @_a_fqdn:
hostnames="$(nix eval .#nixosConfigurations --apply 'c: builtins.attrValues (builtins.mapAttrs (_: x: x.config.networking.fqdn) c)' --json 2>/dev/null | jq '.[]' -r)"; \ 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; \ 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..." 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; \
gum <<<"$hostnames" filter --placeholder "Pick a host..." --no-limit
@remote-current: @remote-current:
>&2 echo Current remote: $(remote-host) >&2 echo Current remote: $(remote-host)
@remote-list: @remote-list:
tomlq <.remote.toml '.hosts | to_entries[] | "remote-set \(.key+1) # -> \(.value.host)"' -r tomlq <.remote.toml '.hosts | to_entries[] | "remote-set \(.key+1) # -> \(.value.host)"' -r
@remote-set remote=`just remote-current && just _a-remote-label`: @remote-set remote=`just remote-current && just _a_remote_label`:
remote-set {{remote}} remote-set {{remote}}
@_a-remote-label: @_a_remote_label:
just remote-list | gum filter --placeholder "Pick a remote..." | cut -d' ' -f2 just remote-list | gum filter --placeholder "Pick a remote..." | cut -d' ' -f2
@_a-remote-fqdn: @_some_remote_labels:
just remote-list | gum filter --placeholder "Pick remotes..." --no-limit | cut -d' ' -f2
@_a_remote_fqdn:
just remote-list | gum filter --placeholder "Pick a remote..." | cut -d' ' -f5- just remote-list | gum filter --placeholder "Pick a remote..." | cut -d' ' -f5-
@_some_remote_fqdns:
just remote-list | gum filter --placeholder "Pick remote..." --no-limit | cut -d' ' -f5-
@_remote_ensure hostname=`just _a_fqdn`: @_remote_ensure hostname=`just _a_fqdn`:
if test ! -s .remote.toml; then remote-init "{{ hostname }}"; \ if test ! -s .remote.toml; then remote-init "{{ hostname }}"; \
elif tomlq <.remote.toml '.hosts | to_entries[] |.value.host' -r | grep -q "{{ hostname }}"; then true; \ elif tomlq <.remote.toml '.hosts | to_entries[] |.value.host' -r | grep -q "{{ hostname }}"; then true; \
@ -91,12 +110,17 @@ inspect-config host=`just _a_host`:
fi fi
@_remote_label_from_fqdn hostname=`just _a_fqdn`: @_remote_label_from_fqdn hostname=`just _a_fqdn`:
tomlq <.remote.toml '.hosts | to_entries[] | select(.value.host == "{{ hostname }}") | .key' -r tomlq <.remote.toml '.hosts | to_entries[] | select(.value.host == "{{ hostname }}") | .key+1' -r
@remote-mprocs +$cmd=`printf "just %s\n" $(just --summary --unsorted) | gum filter --placeholder "Pick a recipie..."`:
just _some_remote_labels | sed -E 's/(.*)/remote --label="\1" "env NIX_NO_NOM=1 $cmd"/g' | xargs -d'\n' mprocs
@remote-mprocs-new +$cmd=`printf "just %s\n" $(just --summary --unsorted) | gum filter --placeholder "Pick a recipie..."`:
just _some_fqdns | xe -s 'just _remote_ensure "$1"; just _remote_label_from_fqdn "$1"' | sed -E 's/(.*)/remote --label="\1" "env NIX_NO_NOM=1 $cmd"/g' | xargs -d'\n' mprocs
# TODO: support multiple labels, run in tmux # TODO: support multiple labels, run in tmux
remote label=`just _a-remote-label` cmd=`printf "just %s\n" $(just --summary --unsorted) | gum filter --placeholder "Pick a recipie..."`: #remote label=`just _a_remote_label` cmd=`printf "just %s\n" $(just --summary --unsorted) | gum filter --placeholder "Pick a recipie..."`:
remote --label={{label}} {{cmd}} # remote --label={{label}} {{cmd}}
# TODO: packaged as nix-web # TODO: packaged as nix-web
@gorgon: @gorgon: