Compare commits

..

3 commits

Author SHA1 Message Date
912be37cc0
freeze it up 2024-09-03 15:01:16 -05:00
af28544102
implement cache 2024-09-03 12:17:01 -05:00
dba9b0c0e1
semantics 2024-09-03 12:01:32 -05:00
5 changed files with 45 additions and 12 deletions

View file

@ -8,5 +8,6 @@
cachix
graphviz
typst
charm-freeze
]);
}

View file

@ -33,16 +33,16 @@ overlay:
echo nixosConfigAttrs().join(" ")
proc update(yes: bool = false) =
## *TBD* update and run nixos-rebuild
## *TBI* update and run nixos-rebuild
fatal "not implemented"
proc build(minimal: bool = false) =
## nix build
nixBuild(minimal, rest)
proc cache(name: string = "daylin") =
## *TBD* build and push to cachix
fatal "not implemented"
proc cache(minimal: bool = false, name: string = "daylin") =
## build and push to cachix
nixBuildWithCache(minimal, name, rest)
proc osCmd() =
## nixos-rebuild
@ -52,12 +52,11 @@ overlay:
error (
&"unknown nixos-rebuild subcmd: {subcmd}\nexpected one of: \n" &
nixosSubcmds.mapIt(" " & it).join("\n")
)
quit QuitFailure
); quit QuitFailure
nixosRebuild(subcmd, rest[1..^1])
proc ci(`ref`: string = "main") =
## *TBD* trigger GHA update flow
## trigger GHA update flow
if rest.len == 0:
fatal "expected workflow file name"; quit QuitFailure
createDispatch(rest[0], `ref`)
@ -67,7 +66,7 @@ proc checkExes() =
quit("oizys requires nix", QuitFailure)
proc `//`(t1: Table[string, string], t2: Table[string, string]): Table[string, string] =
# nix style table merge
# nix style shallow table merge
for k, v in t1.pairs(): result[k] = v
for k, v in t2.pairs(): result[k] = v

View file

@ -6,7 +6,7 @@ import std/[
import ./spin
func addArgs*(cmd: var string, args: seq[string]) =
func addArgs*(cmd: var string, args: openArray[string]) =
cmd &= " " & args.join(" ")
func addArg*(cmd: var string, arg: string) =

View file

@ -38,7 +38,7 @@ const defaultFlushThreshold = lvlAll
proc genFmtStr(
fmtPrefix, fmtSep, fmtSuffix, levelBb: string,
level: Level
): string =
): string =
var parts: seq[string]
if fmtPrefix != "": parts.add fmtPrefix
parts.add $LevelNames[level].bb(levelBb)
@ -58,8 +58,8 @@ proc newFancyConsoleLogger*(
warnBb: string = "bold yellow",
errorBb: string = "bold red",
fatalBb: string = "bold red"
): FancyConsoleLogger =
## Creates a new `ColoredConsoleLogger<#ConsoleLogger>`_.
): FancyConsoleLogger =
## Creates a new `FancyConsoleLogger<#ConsoleLogger>`_.
new result
let fmtStrs: array[Level, string] = [
genFmtStr(fmtPrefix,fmtSep, fmtSuffix, "", lvlAll),

View file

@ -203,10 +203,12 @@ proc nixBuildHostDry*(minimal: bool, rest: seq[string]) =
quit "exiting...", QuitSuccess
cmd.addArgs drvs
cmd.addArg "--no-link"
if isCi():
writeDervationsToStepSummary drvs
else:
cmd.addArgs nixosConfigAttrs()
cmd.addArg "--dry-run"
cmd.addArgs rest
let (_, err) =
@ -214,4 +216,35 @@ proc nixBuildHostDry*(minimal: bool, rest: seq[string]) =
let output = parseDryRunOutput err
display output
# TODO: Add to bbansi
template `bbfmt`(pattern: static string): untyped =
bb(fmt(pattern))
proc nixBuildWithCache*(minimal: bool, name: string, rest:seq[string]) =
if findExe("cachix") == "":
fatal "is cachix installed?"; quit QuitFailure
info bbfmt"building and pushing to cache: [b]{name}"
var cmd = "cachix"
cmd.addArgs ["watch-exec","--"]
cmd.addArg "nix build"
if minimal:
debug "populating args with derivations not built/cached"
let drvs = systemPathDrvsToBuild()
if drvs.len == 0:
info "nothing to build"
quit "exiting...", QuitSuccess
cmd.addArgs drvs
cmd.addArg "--no-link"
else:
cmd.addArgs nixosConfigAttrs()
cmd.addArgs rest
debug cmd
quit QuitSuccess
let err = runCmd(cmd)
quit err