diff --git a/pkgs/oizys/src/oizys.nim b/pkgs/oizys/src/oizys.nim index 7e92c17..688fb8a 100644 --- a/pkgs/oizys/src/oizys.nim +++ b/pkgs/oizys/src/oizys.nim @@ -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"]) diff --git a/pkgs/oizys/src/oizys/context.nim b/pkgs/oizys/src/oizys/context.nim index b15d71d..fca6158 100644 --- a/pkgs/oizys/src/oizys/context.nim +++ b/pkgs/oizys/src/oizys/context.nim @@ -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: diff --git a/pkgs/oizys/src/oizys/exec.nim b/pkgs/oizys/src/oizys/exec.nim index 8a865a5..6acb694 100644 --- a/pkgs/oizys/src/oizys/exec.nim +++ b/pkgs/oizys/src/oizys/exec.nim @@ -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 diff --git a/pkgs/oizys/src/oizys/nix.nim b/pkgs/oizys/src/oizys/nix.nim index 3bdaae3..e8e3477 100644 --- a/pkgs/oizys/src/oizys/nix.nim +++ b/pkgs/oizys/src/oizys/nix.nim @@ -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 diff --git a/todo.md b/todo.md index b269e21..974c22d 100644 --- a/todo.md +++ b/todo.md @@ -2,8 +2,7 @@ ## oizys -- [ ] add deployment capability that expands `oizys os ` with a `--remote` flag and utilizes `nixos-rebuild --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