implement cache

This commit is contained in:
Daylin Morgan 2024-09-03 12:17:01 -05:00
parent dba9b0c0e1
commit af28544102
Signed by: daylin
GPG key ID: 950D13E9719334AD
3 changed files with 38 additions and 5 deletions

View file

@ -40,9 +40,9 @@ overlay:
## nix build
nixBuild(minimal, rest)
proc cache(name: string = "daylin") =
## *TBI* 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
@ -56,7 +56,7 @@ overlay:
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`)

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

@ -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