new and improved hwylterm

This commit is contained in:
Daylin Morgan 2024-11-06 22:48:59 -06:00
parent 7518c884c1
commit d4d76d4a3d
Signed by: daylin
GPG key ID: 950D13E9719334AD
4 changed files with 109 additions and 120 deletions

View file

@ -8,7 +8,7 @@ buildNimblePackage {
verions = "unstable"; verions = "unstable";
src = lib.cleanSource ./.; src = lib.cleanSource ./.;
nativeBuildInputs = [ openssl ]; nativeBuildInputs = [ openssl ];
nimbleDepsHash = "sha256-0F/rKcLUH95vW3ODB2mgMQ2klbN9rjMeP+LUK0Ucj2w="; nimbleDepsHash = "sha256-YCHyMyy6cvNZgsmxPgskbAMETHs4/bP2Cp6XbjfWm1k=";
meta = { meta = {
description = "nix begat oizys"; description = "nix begat oizys";

View file

@ -1,24 +1,14 @@
{ {
"version": 2, "version": 2,
"packages": { "packages": {
"cligen": {
"version": "1.7.7",
"vcsRevision": "f50f887eacfe33866e22f8a0d322e29a1c830cf9",
"url": "https://github.com/c-blake/cligen.git",
"downloadMethod": "git",
"dependencies": [],
"checksums": {
"sha1": "237596b6be88dcf9ee0bd9732a7baaac526f0c07"
}
},
"hwylterm": { "hwylterm": {
"version": "0.1.0", "version": "0.1.0",
"vcsRevision": "56bb2bb7c1da402c2c52fb3f7f10620c7c2fca7e", "vcsRevision": "a4e0f3fc7b34bac8e448dd35f58012d07dd4a0d0",
"url": "https://github.com/daylinmorgan/hwylterm", "url": "https://github.com/daylinmorgan/hwylterm",
"downloadMethod": "git", "downloadMethod": "git",
"dependencies": [], "dependencies": [],
"checksums": { "checksums": {
"sha1": "8810cf69a74de580e1ab08f0c153afbf33c8a98e" "sha1": "848f75dc1bc910560e5e0038bf0a9ebf8d096385"
} }
}, },
"jsony": { "jsony": {

View file

@ -11,8 +11,7 @@ bin = @["oizys"]
# Dependencies # Dependencies
requires "nim >= 2.0.8" requires "nim >= 2.0.8"
requires "cligen"
requires "jsony" requires "jsony"
requires "zippy" requires "zippy"
requires "https://github.com/daylinmorgan/hwylterm#HEAD" requires "https://github.com/daylinmorgan/hwylterm#a4e0f3f"

View file

@ -1,44 +1,108 @@
## nix begat oizys ## nix begat oizys
import std/[os, osproc, tables, sequtils, strformat, strutils] import std/[os, osproc, sequtils, strformat, strutils]
import hwylterm, hwylterm/[cligen, logging] import hwylterm, hwylterm/[hwylcli, logging]
import oizys/[context, github, nix, overlay, logging] import oizys/[context, github, nix, logging]
proc checkExes() =
if findExe("nix") == "":
fatalQuit "oizys requires nix"
proc confirm(q: string): bool = checkexes()
stderr.write $(q & bb"[yellow] (Y/n) ") hwylCli:
while true: name "oizys"
let ans = readLine(stdin) globalFlags:
case ans.strip().toLowerAscii(): flake "path/to/flake"
of "y","yes": return true host:
of "n","no": return false T seq[string]
else: ? "host(s) to build"
stderr.write($bb("[red]Please answer Yes/no\nexpected one of [b]Y,yes,N,no ")) # - h conflicts with autoadded help short flag
stderr.write "\n" debug:
T bool
overlay: ? "enable debug mode"
proc pre( - d
flake: string = "", resetCache:
host: seq[string] = @[], T bool
debug: bool = false, ? "set cache timeout to 0"
resetCache: bool = false, - r
rest: seq[string], preSub:
) =
setupLoggers(debug) setupLoggers(debug)
updateContext(host, flake, debug, resetCache) updateContext(host, flake, debug, resetCache)
subcommands:
proc dry(minimal: bool = false) = --- build
## dry run build ... "nix build"
nixBuildHostDry(minimal, rest) flags:
minimal:
T bool
- m
run:
nixBuild(minimal, args)
proc output(yes: bool = false) = --- cache
## nixos config attr ... "build and push store paths"
flags:
name:
* "oizys"
? "name of binary cache"
service:
* "attic"
jobs:
* countProcessors()
? "jobs when pushing paths"
T int
run:
nixBuildWithCache(name, args, service, jobs)
--- ci
... "trigger GHA"
flags:
`ref`:
? "git ref/branch/tag to trigger workflow on"
* "main"
run:
if args.len == 0: fatalQuit "expected workflow file name"
createDispatch(args[0], `ref`)
--- dry
... "dry run build"
flags:
minimal:
T bool
run:
nixBuildHostDry(minimal, args)
--- os
? "[b]oizys os[/] [i]subcmd[/] [[[faint]flags[/]]"
... "nixos-rebuild [italic]subcmd[/]"
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])
--- output
... "nixos config attr"
flags:
yes:
T bool
? "skip all confirmation prompts"
run:
echo nixosConfigAttrs().join(" ") echo nixosConfigAttrs().join(" ")
proc update( --- update
yes: bool = false, ... "update and run nixos-rebuild"
preview: bool = false flags:
) = yes:
## update and run nixos-rebuild T bool
? "skip all confirmation prompts"
preview:
T bool
? "show preview and exit"
run:
let hosts = getHosts() let hosts = getHosts()
if hosts.len > 1: fatalQuit "operation only supports one host" if hosts.len > 1: fatalQuit "operation only supports one host"
let run = getLastUpdateRun() let run = getLastUpdateRun()
@ -49,67 +113,3 @@ overlay:
updateRepo() updateRepo()
nixosRebuild("switch") nixosRebuild("switch")
proc build(minimal: bool = false) =
## nix build
nixBuild(minimal, rest)
proc cache(name: string = "oizys", service: string = "attic", jobs: int = countProcessors()) =
## build and push store paths
nixBuildWithCache(name, rest, service, jobs)
proc osCmd() =
## nixos-rebuild
if len(rest) == 0: fatalQuit "please provide subcmd"
let subcmd = rest[0]
if subcmd notin nixosSubcmds:
fatalQuit(
&"unknown nixos-rebuild subcmd: {subcmd}\nexpected one of: \n" &
nixosSubcmds.mapIt(" " & it).join("\n")
)
nixosRebuild(subcmd, rest[1..^1])
proc ci(`ref`: string = "main") =
## trigger GHA
if rest.len == 0: fatalQuit "expected workflow file name"
createDispatch(rest[0], `ref`)
proc checkExes() =
if findExe("nix") == "":
fatalQuit "oizys requires nix"
when isMainModule:
import cligen
checkExes()
hwylCli(clCfg)
const
sharedHelp = //{
"flake" : "path/to/flake",
"host" : "host(s) to build",
"debug" : "enable debug mode",
"resetCache" : "set cache timeout to 0"
}
updateHelp = //{
"yes" : "skip all confirmation prompts"
} // sharedHelp
ciHelp = //{
"ref" : "git ref/branch/tag to trigger workflow on"
}
cacheHelp = //{
"name" : "name of cachix binary cache",
"jobs" : "jobs when pushing paths"
} // sharedHelp
let
osUsage = $bb("$command [[subcmd] $args\n$doc[bold]Options[/]:\n$options")
dispatchMulti(
[build, help = sharedHelp, usage = clCfg.use ],
[cache, help = cacheHelp , usage = clCfg.use ],
[ci, help = ciHelp , usage = clCfg.use ],
[dry, help = sharedHelp, usage = clCfg.use ],
[osCmd, help = sharedHelp, usage = osUsage, cmdName = "os"],
[output, help = sharedHelp, usage = clCfg.use],
[update, help = updateHelp, usage = clCfg.use],
)