move os update script to repo bin and call via just
3 files changed, 51 insertions(+), 56 deletions(-)
changed files
A bin/os_update_remote
@@ -0,0 +1,35 @@ +#!/usr/bin/env fish + +argparse --move-unknown "r/remote&" "b/build-host=&" "e/elevation-strategy=&" -- $argv + +set --local target $argv[1] +set --local actions $argv[2] switch + +set --local user_regex '(?<user>[[:graph:]]+)' +set --local host_regex '(?<host>[[:alnum:]\-]*)' +set --local fqdn_regex "(?<fqdn>$host_regex(?:\.[[:alnum:]\-.]+)?)" +string match --quiet --regex --groups-only "(?:$user_regex@)?$fqdn_regex" $target + +set --local action $actions[1] +set --local build_host $_flag_build_host $target + +set --local elevation_strategy $_flag_elevation_strategy ( + if test "$user" = "root" + echo none + else + echo passwordless + end +) + +if set --query _flag_remote; or set --query _flag_build_host + set --function build_host_arg --build-host $build_host[1] +end + +nh os $action \ + --file . nixosConfigurations.{$host} \ + $build_host_arg \ + --use-substitutes \ + --target-host {$target} \ + --show-trace \ + --elevation-strategy $elevation_strategy[1] \ + $argv_opts
M justfile → justfile
@@ -9,19 +9,24 @@ test: nix flake check --all-systems path:. -build *args: - nh home switch --file . "homeConfigurations.{{ user }}@{{ hostname }}" {{ args }} +build action="switch" *args: + nh home {{ action }} --file . "homeConfigurations.{{ user }}@{{ hostname }}" {{ args }} -run action="switch" *args: +[linux] +os-update action="switch" *args: + nh os {{ action }} --file . nixosConfigurations.{{ hostname }} {{ args }} + +[macos] +os-update action="switch" *args: + nh darwin {{ action }} --file . darwinConfigurations.{{ hostname }} {{ args }} + +run target="" *args: #!/usr/bin/env fish - set --local os $(string split -- - $system)[-1] - switch $os: - case "darwin": - nh darwin {{ action }} --file . darwinConfigurations.{{ hostname }} {{ args }} - case "linux": - nh os {{ action }} --file . nixosConfigurations.{{ hostname }} {{ args }} - case *: - echo "Couldn't find a supported os in \$system: $system" + switch "{{ target }}" + case {{ hostname }} . "" + just os-update {{ args }} + case '*' + ./bin/os_update_remote {{ target }} {{ args }} end update-packages:
D scripts/os/update
@@ -1,45 +0,0 @@ -#!/usr/bin/env fish -# update server with nixos-rebuild - -if test (path basename $PWD) != nixfiles - echo "not in nixfiles directory!" >&2 - return 1 -end - -argparse --move-unknown "r/remote&" "b/build-host=&" "e/elevation-strategy=&" -- $argv - -set --local target "$argv[1]" -if test -z $target - echo "please specify target hostname" >&2 - return 1 -end - -set --local user_regex '(?<user>[[:graph:]]+)' -set --local host_regex '(?<host>[[:alnum:]\-]*)' -set --local fqdn_regex "(?<fqdn>$host_regex(?:\.[[:alnum:]\-.]+)?)" -string match --quiet --regex --groups-only "(?:$user_regex@)?$fqdn_regex" $target - -set --local actions $argv[2] switch -set --local action $actions[1] -set --local build_host $_flag_build_host $target - -set --local elevation_strategy $_flag_elevation_strategy ( - if test "$user" = "root" - echo none - else - echo passwordless - end -) - -if set --query _flag_remote; or set --query _flag_build_host - set --function build_host_arg --build-host $build_host[1] -end - -nh os $action \ - --file . nixosConfigurations.{$host} \ - $build_host_arg \ - --use-substitutes \ - --target-host {$target} \ - --show-trace \ - --elevation-strategy $elevation_strategy[1] \ - $argv_opts