add --remote flag to oizys os

This commit is contained in:
Daylin Morgan 2025-01-07 11:40:54 -06:00
parent 4c0cde004d
commit 637ea85e47
Signed by: daylin
GPG key ID: 950D13E9719334AD
5 changed files with 40 additions and 19 deletions

View file

@ -24,7 +24,6 @@ hwylCli:
- d - d
resetCache: resetCache:
? "set cache timeout to 0" ? "set cache timeout to 0"
- r
[misc] [misc]
yes: yes:
- y - y
@ -111,15 +110,12 @@ hwylCli:
[os] [os]
? "[b]oizys os[/] [i]subcmd[/] [[[faint]flags[/]]" ? "[b]oizys os[/] [i]subcmd[/] [[[faint]flags[/]]"
... "nixos-rebuild [italic]subcmd[/]" ... "nixos-rebuild [italic]subcmd[/]"
flags:
remote:
? "host is remote"
- r
run: run:
if args.len == 0: fatalQuit "please provide subcmd" nixosRebuild(args, remote)
let subcmd = args[0]
if subcmd notin nixosSubcmds:
fatalQuit(
&"unknown nixos-rebuild subcmd: {subcmd}\nexpected one of: \n" &
nixosSubcmds.mapIt(" " & it).join("\n")
)
nixosRebuild(subcmd, args[1..^1])
[output] [output]
... "nixos config attr" ... "nixos config attr"
@ -148,5 +144,5 @@ hwylCli:
if preview: quit 0 if preview: quit 0
if yes or confirm("Proceed with system update?"): if yes or confirm("Proceed with system update?"):
updateRepo() updateRepo()
nixosRebuild("switch") nixosRebuild(["switch"])

View file

@ -11,8 +11,10 @@ type
ci: bool ci: bool
resetCache: bool resetCache: bool
let currentHost* = getHostName()
proc initContext*(): OizysContext = proc initContext*(): OizysContext =
result.hosts = @[getHostname()] result.hosts = @[currentHost]
result.flake = "github:daylinmorgan/oizys" result.flake = "github:daylinmorgan/oizys"
let localDir = getHomeDir() / "oizys" let localDir = getHomeDir() / "oizys"
if localDir.dirExists: if localDir.dirExists:

View file

@ -7,9 +7,10 @@ import hwylterm
import hwylterm/spin/spinners # todo: remove after hwylterm update import hwylterm/spin/spinners # todo: remove after hwylterm update
func addArgs*(cmd: var string, args: openArray[string]) = func addArgs*(cmd: var string, args: varargs[string]) =
cmd &= " " & args.join(" ") cmd &= " " & args.join(" ")
# deprecate in favor of above?
func addArg*(cmd: var string, arg: string ) = func addArg*(cmd: var string, arg: string ) =
cmd &= " " & arg cmd &= " " & arg

View file

@ -31,11 +31,34 @@ const nixosSubcmds* =
"""switch boot test build dry-build dry-activate edit """switch boot test build dry-build dry-activate edit
repl build-vm build-vm-with-bootloader list-generations""".splitWhitespace() repl build-vm build-vm-with-bootloader list-generations""".splitWhitespace()
proc nixosRebuild*(subcmd: string, rest: seq[string] = @[]) = proc handleRebuildArgs(args: openArray[string], remote: bool): string =
if getHosts().len > 1: assert args.len > 0
fatalQuit "nixos-rebuild only supports one host" # TODO: future versions will let hwylterm handle arg parseing
var cmd = fmt"sudo nixos-rebuild {subcmd} --flake {getFlake()} --log-format multiline" let subcmd = args[0]
cmd.addArgs rest if subcmd notin nixosSubcmds:
fatalQuit(
"unknown nixos-rebuild subcmd: " &
subcmd &
"\nexpected one of: \n" &
nixosSubcmds.mapIt(" " & it).join("\n")
)
if not remote: result.add "sudo"
result.addArgs "nixos-rebuild"
result.addArgs subcmd
result.addArgs "--flake", getFlake()
result.addArgs "--log-format multiline"
if remote:
let host = getHosts()[0]
if host == currentHost:
fatalQuit "did you mean to specify a remote host?"
result.addArgs "--target-host", host, "--use-remote-sudo"
result.addArgs args[1..^1]
proc nixosRebuild*(args: openArray[string], remote: bool = false) =
if getHosts().len > 1: fatalQuit "nixos-rebuild only supports one host"
if args.len == 0: fatalQuit "please provide subcmd"
let cmd = handleRebuildArgs(args, remote)
quitWithCmd cmd quitWithCmd cmd
type type

View file

@ -2,8 +2,7 @@
## oizys ## oizys
- [ ] add deployment capability that expands `oizys os <subcmd>` with a `--remote` flag and utilizes `nixos-rebuild <cmd> --target-host` - [ ] reimplement "--debug" flag as verbosity count i.e. "-vv"/ "--verbose --verbose"
basically `oizys os switch --host algiz --remote` is translated to `nixos-rebuild switch --flake . --target-host algiz --use-remote-sudo`
## software ## software