mirror of
https://github.com/daylinmorgan/oizys.git
synced 2024-12-22 14:20:44 -06:00
Compare commits
No commits in common. "7ebcb32b6305a0607b1cb929cb27bbb3ef3e6cb6" and "853678a1a93638c5e2b852ee9351c4f282df7b16" have entirely different histories.
7ebcb32b63
...
853678a1a9
2 changed files with 13 additions and 53 deletions
|
@ -1,7 +1,7 @@
|
|||
import std/[
|
||||
algorithm, json,
|
||||
enumerate, os, sequtils, strformat,
|
||||
strutils, sugar, logging, tables, times
|
||||
strutils, sugar, logging, tables
|
||||
]
|
||||
import hwylterm, hwylterm/logging, jsony
|
||||
|
||||
|
@ -119,15 +119,9 @@ proc toBuildNixosConfiguration(): seq[string] =
|
|||
return output.toBuild.mapIt(it.storePath)
|
||||
|
||||
type
|
||||
DerivationOutputsOut = object
|
||||
path: string
|
||||
DerivationOutputs = object
|
||||
`out`: DerivationOutputsOut
|
||||
NixDerivation = object
|
||||
inputDrvs: Table[string, JsonNode]
|
||||
name: string
|
||||
outputs: DerivationOutputs
|
||||
|
||||
|
||||
proc evaluateDerivations(drvs: seq[string]): Table[string, NixDerivation] =
|
||||
var cmd = "nix derivation show -r"
|
||||
|
@ -172,54 +166,18 @@ func isIgnored(drv: string): bool =
|
|||
if name.startswith(pkg):
|
||||
return true
|
||||
|
||||
# proc systemPathDrvsToBuild(): seq[string] =
|
||||
|
||||
type
|
||||
OizysDerivation = object
|
||||
drv: NixDerivation # do i need this ?
|
||||
output: string
|
||||
name: string
|
||||
|
||||
iterator getSystemPathDrvs(drvs: Table[string, NixDerivation]): string =
|
||||
let systemPaths = findSystemPaths(drvs)
|
||||
for p in systemPaths:
|
||||
for d in drvs[p].inputDrvs.keys():
|
||||
yield d
|
||||
|
||||
proc getOizysDerivations(): seq[OizysDerivation] =
|
||||
let toBuild = toBuildNixosConfiguration()
|
||||
let drvs = evaluateDerivations(nixosConfigAttrs())
|
||||
|
||||
for name in getSystemPathDrvs(drvs):
|
||||
if name in toBuild and not isIgnored(name):
|
||||
let nixDrv = drvs[name]
|
||||
result.add OizysDerivation(
|
||||
name: name,
|
||||
output: nixDrv.outputs.`out`.path,
|
||||
drv: nixDrv,
|
||||
)
|
||||
|
||||
proc systemPathDrvsToBuild(): seq[string] =
|
||||
var inputDrvs, dropped: seq[string]
|
||||
let toBuild = toBuildNixosConfiguration()
|
||||
let drvs = evaluateDerivations(nixosConfigAttrs())
|
||||
|
||||
let systemPaths = findSystemPaths(drvs)
|
||||
for p in systemPaths:
|
||||
inputDrvs &= drvs[p].inputDrvs.keys().toSeq()
|
||||
|
||||
(result, _) = filterSeq(inputDrvs, (s) => s in toBuild)
|
||||
(dropped, result) = filterSeq(result, isIgnored)
|
||||
echo "SOMETHING SHOULD HAPPEN HERE!"
|
||||
for drv in result:
|
||||
echo drv
|
||||
echo drvs[drv]
|
||||
|
||||
|
||||
debug fmt"ignored {dropped.len} derivations"
|
||||
result = result.mapIt(it & "^*")
|
||||
|
||||
|
||||
func splitDrv(drv: string): tuple[name, hash:string] =
|
||||
let s = drv.split("-", 1)
|
||||
(s[1].replace(".drv^*",""),s[0].split("/")[^1])
|
||||
|
@ -282,27 +240,28 @@ proc nixBuildWithCache*(name: string, rest:seq[string], service: string, jobs: i
|
|||
if findExe(service) == "": fatalQuit fmt"is {service} installed?"
|
||||
info bbfmt"building and pushing to cache: [b]{name}"
|
||||
debug "determining missing cache hits"
|
||||
let drvs = getOizysDerivations()
|
||||
let drvs = systemPathDrvsToBuild()
|
||||
if drvs.len == 0:
|
||||
info "nothing to build"
|
||||
quit "exiting...", QuitSuccess
|
||||
|
||||
# TODO: add back reporting to GITHUB SUMMARY
|
||||
var outs: seq[string]
|
||||
# TODO: add back reporting to GITHUB SUMMARY
|
||||
# include time to build?
|
||||
for drv in drvs:
|
||||
let startTime = now()
|
||||
var cmd = "nix build"
|
||||
cmd.addArg drv.name & "^*"
|
||||
cmd.addArg drv
|
||||
cmd.addArg "--no-link"
|
||||
# cmd.addArg "--print-out-paths"
|
||||
# cmd.addArg "-L"
|
||||
cmd.addArg "--print-out-paths"
|
||||
cmd.addArg "-L"
|
||||
cmd.addArgs rest
|
||||
let buildCode = runCmd(cmd)
|
||||
let (path, _, buildCode) = runCmdCapt(cmd)
|
||||
if buildCode != 0:
|
||||
error "failed to build: " & drv.name
|
||||
# TODO: propagate errors using nix log?
|
||||
error "failed to build: " & drv
|
||||
continue
|
||||
info "build duration: " & $(now() - startTime)
|
||||
outs &= drv.output
|
||||
|
||||
outs &= path.strip().splitLines()
|
||||
|
||||
var cmd = service
|
||||
cmd.addArg "push"
|
||||
|
@ -314,3 +273,4 @@ proc nixBuildWithCache*(name: string, rest:seq[string], service: string, jobs: i
|
|||
if pushErr != 0:
|
||||
errorQuit "failed to push build to cache"
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue