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