update oizys cli with newer hwylterm

This commit is contained in:
Daylin Morgan 2025-01-23 18:21:06 -06:00
parent 00fb07a64f
commit 7d68c9549c
Signed by: daylin
GPG key ID: 950D13E9719334AD
6 changed files with 36 additions and 37 deletions

View file

@ -8,7 +8,7 @@ buildNimblePackage {
version = "unstable"; version = "unstable";
src = lib.cleanSource ./.; src = lib.cleanSource ./.;
nativeBuildInputs = [ openssl ]; nativeBuildInputs = [ openssl ];
nimbleDepsHash = "sha256-dFJw/m7D5UFUrHH7exsyHknt8WHIK1QIQATNd5l7FZA="; nimbleDepsHash = "sha256-2xuTo85qPZtcNGlcD5/SXkRN73srbTBVtiPtFYmq2Ww=";
meta = { meta = {
description = "nix begat oizys"; description = "nix begat oizys";

View file

@ -3,12 +3,12 @@
"packages": { "packages": {
"hwylterm": { "hwylterm": {
"version": "0.1.0", "version": "0.1.0",
"vcsRevision": "3cf572ea4afa6f895eb0897bfb8e6e35f8f1e953", "vcsRevision": "c40a0a2038338b6bbaa4179c76452f6f0d1ac87c",
"url": "https://github.com/daylinmorgan/hwylterm", "url": "https://github.com/daylinmorgan/hwylterm",
"downloadMethod": "git", "downloadMethod": "git",
"dependencies": [], "dependencies": [],
"checksums": { "checksums": {
"sha1": "bf33d39e2a451b89fbbff6418569ccd5428b6bfd" "sha1": "ba253b8643c6cd5abf98de5e1c89f961e14dc87c"
} }
}, },
"jsony": { "jsony": {

View file

@ -13,5 +13,5 @@ bin = @["oizys"]
requires "nim >= 2.0.8" requires "nim >= 2.0.8"
requires "jsony" requires "jsony"
requires "zippy" requires "zippy"
requires "https://github.com/daylinmorgan/hwylterm#3cf572ea" requires "https://github.com/daylinmorgan/hwylterm#c40a0a2"

View file

@ -39,6 +39,8 @@ hwylCli:
subcommands: subcommands:
[build] [build]
... "nix build" ... "nix build"
positionals:
args seq[string]
flags: flags:
^minimal ^minimal
nom: nom:
@ -48,6 +50,8 @@ hwylCli:
[cache] [cache]
... "build and push store paths" ... "build and push store paths"
positionals:
args seq[string]
flags: flags:
name: name:
T string T string
@ -75,6 +79,8 @@ hwylCli:
subcommands: subcommands:
[update] [update]
... "build current and updated hosts" ... "build current and updated hosts"
positionals:
args seq[string]
run: run:
ciUpdate(args) ciUpdate(args)
@ -85,6 +91,8 @@ hwylCli:
examples: examples:
[b]oizys gha update[/] --inputs:hosts:othalan,algiz,mannaz [b]oizys gha update[/] --inputs:hosts:othalan,algiz,mannaz
""" """
positionals:
workflow string
flags: flags:
inputs: inputs:
T seq[KVString] T seq[KVString]
@ -96,13 +104,14 @@ hwylCli:
run: run:
# TODO: support file operations like gh # TODO: support file operations like gh
# i.e. @flake.lock means read a file at flake.lock and use it's contents as a string # i.e. @flake.lock means read a file at flake.lock and use it's contents as a string
if args.len == 0: fatalQuit "expected workflow file name"
let inputs = let inputs =
inputs.mapIt((it.key, it.val)).toTable() inputs.mapIt((it.key, it.val)).toTable()
createDispatch(args[0], `ref`, inputs) createDispatch(workflow, `ref`, inputs)
[dry] [dry]
... "dry run build" ... "dry run build"
positionals:
args seq[string]
flags: flags:
^minimal ^minimal
run: run:
@ -111,12 +120,15 @@ 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[/]"
positionals:
subcmd NixosRebuildSubcmd
args seq[string]
flags: flags:
remote: remote:
? "host is remote" ? "host is remote"
- r - r
run: run:
nixosRebuild(args, remote) nixosRebuild(subcmd, args, remote)
[output] [output]
... "nixos config attr" ... "nixos config attr"
@ -145,5 +157,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(NixosRebuildSubcmd.switch)

View file

@ -56,17 +56,14 @@ proc runCmdCapt*(
close p close p
proc formatStdoutStderr(stdout: string, stderr: string): string = proc formatStdoutStderr(stdout: string, stderr: string): BbString =
template show(stream: string) = template add(stream: string) =
if stream.strip() != "": if stream.strip() != "":
result.add astToStr(stream) & ":\n" result.add astToStr(stream).bb("bold") & ":\n"
for line in stream.splitlines(): for line in stream.splitlines():
# TODO: make -> red after hwylterm update result.add bb("[red]->[/] " & line & "\n")
result.add "-> " add(stdout)
result.add line add(stderr)
result.add "\n"
show(stdout)
show(stderr)
proc runCmdCaptWithSpinner*( proc runCmdCaptWithSpinner*(
cmd: string, cmd: string,
@ -79,7 +76,7 @@ proc runCmdCaptWithSpinner*(
with(Dots2, msg): with(Dots2, msg):
(output, err, code) = runCmdCapt(cmd, capture) (output, err, code) = runCmdCapt(cmd, capture)
if code != 0: if code != 0:
stderr.write(formatStdoutStderr(output,err)) stderr.write($formatStdoutStderr(output,err))
error fmt"{cmd} had non zero exit" error fmt"{cmd} had non zero exit"
quit code quit code
return (output, err) return (output, err)

View file

@ -27,24 +27,15 @@ proc nixosConfigAttrs*(): seq[string] =
for host in getHosts(): for host in getHosts():
result.add nixosConfigAttr(host) result.add nixosConfigAttr(host)
const nixosSubcmds* = type
"""switch boot test build dry-build dry-activate edit NixosRebuildSubcmd* = enum
repl build-vm build-vm-with-bootloader list-generations""".splitWhitespace() switch, boot, test, build, `dry-build`,`dry-activate`, `edit`,
repl, `build-vm`, `build-vm-with-bootloader`, `list-generations`
proc handleRebuildArgs(args: openArray[string], remote: bool): string = proc handleRebuildArgs(subcmd: NixosRebuildSubcmd, 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" if not remote: result.add "sudo"
result.addArgs "nixos-rebuild" result.addArgs "nixos-rebuild"
result.addArgs subcmd result.addArgs $subcmd
result.addArgs "--flake", getFlake() result.addArgs "--flake", getFlake()
result.addArgs "--log-format multiline" result.addArgs "--log-format multiline"
if remote: if remote:
@ -55,10 +46,9 @@ proc handleRebuildArgs(args: openArray[string], remote: bool): string =
result.addArgs args[1..^1] result.addArgs args[1..^1]
proc nixosRebuild*(args: openArray[string], remote: bool = false) = proc nixosRebuild*(subcmd: NixosRebuildSubcmd, args: openArray[string] = [], remote: bool = false) =
if getHosts().len > 1: fatalQuit "nixos-rebuild only supports one host" if getHosts().len > 1: fatalQuit bb"[bold]oizys os[/] only supports one host"
if args.len == 0: fatalQuit "please provide subcmd" let cmd = handleRebuildArgs(subcmd, args, remote)
let cmd = handleRebuildArgs(args, remote)
quitWithCmd cmd quitWithCmd cmd
type type