get oizys cache working

This commit is contained in:
Daylin Morgan 2025-02-10 00:34:15 -06:00
parent 9569bfe4ae
commit 9efec16a82
Signed by: daylin
GPG key ID: 950D13E9719334AD

View file

@ -221,18 +221,18 @@ proc getSystemPathDrvs*(): seq[string] =
for inputDrv, _ in drv.inputDrvs: for inputDrv, _ in drv.inputDrvs:
inputDrv inputDrv
proc getOizysDerivations():Table[string, NixDerivation] =
proc getOizysDerivations(): HashSet[NixDerivation] =
let let
toBuildDrvs = toBuildNixosConfiguration() toBuildDrvs = toBuildNixosConfiguration()
systemPathDrvs = getSystemPathDrvs() systemPathDrvs = getSystemPathDrvs()
toActullyBuildDrvs = systemPathDrvs.filterIt(it in toBuildDrvs and not isIgnored(it)) toActullyBuildDrvs = systemPathDrvs.filterIt(it in toBuildDrvs and not isIgnored(it))
for _ , drv in nixDerivationShow(toActullyBuildDrvs): for path , drv in nixDerivationShow(toActullyBuildDrvs):
result.incl drv result[path] = drv
proc showOizysDerivations*() = proc showOizysDerivations*() =
let drvs = getOizysDerivations() let drvs = getOizysDerivations()
echo drvs.mapIt(it.name & "^*").join("\n") for path, drv in drvs:
echo path & "^*"
# TODO: remove this proc # TODO: remove this proc
proc systemPathDrvsToBuild*(): seq[string] = proc systemPathDrvsToBuild*(): seq[string] =
@ -251,6 +251,7 @@ proc systemPathDrvsToBuild*(): seq[string] =
func splitDrv(drv: string): tuple[name, hash:string] = func splitDrv(drv: string): tuple[name, hash:string] =
assert drv.startsWith("/nix/store"), "is this a /nix/store path? $1" % [drv]
let s = drv.split("-", 1) let s = drv.split("-", 1)
(s[1].replace(".drv",""),s[0].split("/")[^1]) (s[1].replace(".drv",""),s[0].split("/")[^1])
@ -324,20 +325,19 @@ func formatDuration(d: Duration): string =
result.add " and " result.add " and "
result.add $(seconds mod 60) & " seconds" result.add $(seconds mod 60) & " seconds"
proc build(drv: NixDerivation, rest: seq[string]): BuildResult = # TODO: by default collect the build result
proc build(path: string, drv: NixDerivation, rest: seq[string]): BuildResult =
let startTime = now() let startTime = now()
var cmd = "nix build" var cmd = "nix build"
cmd.addArg drv.name & "^*" cmd.addArgs path & "^*", "--no-link"
cmd.addArg "--no-link"
cmd.addArgs rest cmd.addArgs rest
let buildCode = runCmd(cmd) let buildCode = runCmd(cmd)
result.duration = now() - startTime result.duration = now() - startTime
# TODO: make splitDrv more ergonmic?
if buildCode == 0: if buildCode == 0:
result.successful = true result.successful = true
info "succesfully built: " & splitDrv(drv.name).name info "succesfully built: " & splitDrv(path).name
else: else:
warn "failed to build: " & splitDrv(drv.name).name warn "failed to build: " & splitDrv(path).name
info "-> duration: " & formatDuration(result.duration) info "-> duration: " & formatDuration(result.duration)
func outputsPaths(drv: NixDerivation): seq[string] = func outputsPaths(drv: NixDerivation): seq[string] =
@ -361,6 +361,7 @@ proc reportResults(results: seq[(NixDerivation, BuildResult)]) =
output.writeLine rows.join("\n") output.writeLine rows.join("\n")
close output close output
proc prettyDerivation*(path: string): BbString = proc prettyDerivation*(path: string): BbString =
const maxLen = 40 const maxLen = 40
let drv = path.toDerivation() let drv = path.toDerivation()
@ -379,14 +380,20 @@ proc nixBuildWithCache*(name: string, rest: seq[string], service: string, jobs:
info "nothing to build" info "nothing to build"
quit "exiting...", QuitSuccess quit "exiting...", QuitSuccess
info fmt("need to build {drvs.len} derivations:\n") & drvs.mapIt(prettyDerivation(" " & it.outputs["out"].path)).join("\n") # TODO: fix this so it works with table
# info fmt("need to build {drvs.len} derivations:\n") & drvs.mapIt(prettyDerivation(" " & it.outputs["out"].path)).join("\n")
info fmt("need to build {drvs.len} dervations")
for _, drv in drvs:
info prettyDerivation(drv.outputs["out"].path)
if dry: if dry:
quit "exiting...", QuitSuccess quit "exiting...", QuitSuccess
let results = let results =
collect: collect:
for drv in drvs: for path, drv in drvs:
(drv, build(drv, rest)) (drv, build(path, drv, rest))
var outs: seq[string] var outs: seq[string]
for (drv, res) in results: for (drv, res) in results: