mirror of
https://github.com/daylinmorgan/oizys.git
synced 2025-01-22 03:07:31 -06:00
add --remote flag to oizys os
This commit is contained in:
parent
4c0cde004d
commit
637ea85e47
5 changed files with 40 additions and 19 deletions
|
@ -24,7 +24,6 @@ hwylCli:
|
|||
- d
|
||||
resetCache:
|
||||
? "set cache timeout to 0"
|
||||
- r
|
||||
[misc]
|
||||
yes:
|
||||
- y
|
||||
|
@ -111,15 +110,12 @@ hwylCli:
|
|||
[os]
|
||||
? "[b]oizys os[/] [i]subcmd[/] [[[faint]flags[/]]"
|
||||
... "nixos-rebuild [italic]subcmd[/]"
|
||||
flags:
|
||||
remote:
|
||||
? "host is remote"
|
||||
- r
|
||||
run:
|
||||
if args.len == 0: fatalQuit "please provide subcmd"
|
||||
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])
|
||||
nixosRebuild(args, remote)
|
||||
|
||||
[output]
|
||||
... "nixos config attr"
|
||||
|
@ -148,5 +144,5 @@ hwylCli:
|
|||
if preview: quit 0
|
||||
if yes or confirm("Proceed with system update?"):
|
||||
updateRepo()
|
||||
nixosRebuild("switch")
|
||||
nixosRebuild(["switch"])
|
||||
|
||||
|
|
|
@ -11,8 +11,10 @@ type
|
|||
ci: bool
|
||||
resetCache: bool
|
||||
|
||||
let currentHost* = getHostName()
|
||||
|
||||
proc initContext*(): OizysContext =
|
||||
result.hosts = @[getHostname()]
|
||||
result.hosts = @[currentHost]
|
||||
result.flake = "github:daylinmorgan/oizys"
|
||||
let localDir = getHomeDir() / "oizys"
|
||||
if localDir.dirExists:
|
||||
|
|
|
@ -7,9 +7,10 @@ import hwylterm
|
|||
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(" ")
|
||||
|
||||
# deprecate in favor of above?
|
||||
func addArg*(cmd: var string, arg: string ) =
|
||||
cmd &= " " & arg
|
||||
|
||||
|
|
|
@ -31,11 +31,34 @@ const nixosSubcmds* =
|
|||
"""switch boot test build dry-build dry-activate edit
|
||||
repl build-vm build-vm-with-bootloader list-generations""".splitWhitespace()
|
||||
|
||||
proc nixosRebuild*(subcmd: string, rest: seq[string] = @[]) =
|
||||
if getHosts().len > 1:
|
||||
fatalQuit "nixos-rebuild only supports one host"
|
||||
var cmd = fmt"sudo nixos-rebuild {subcmd} --flake {getFlake()} --log-format multiline"
|
||||
cmd.addArgs rest
|
||||
proc handleRebuildArgs(args: openArray[string], remote: bool): string =
|
||||
assert args.len > 0
|
||||
# TODO: future versions will let hwylterm handle arg parseing
|
||||
let subcmd = args[0]
|
||||
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
|
||||
|
||||
type
|
||||
|
|
3
todo.md
3
todo.md
|
@ -2,8 +2,7 @@
|
|||
|
||||
## oizys
|
||||
|
||||
- [ ] add deployment capability that expands `oizys os <subcmd>` with a `--remote` flag and utilizes `nixos-rebuild <cmd> --target-host`
|
||||
basically `oizys os switch --host algiz --remote` is translated to `nixos-rebuild switch --flake . --target-host algiz --use-remote-sudo`
|
||||
- [ ] reimplement "--debug" flag as verbosity count i.e. "-vv"/ "--verbose --verbose"
|
||||
|
||||
## software
|
||||
|
||||
|
|
Loading…
Reference in a new issue