Update ERIS and record URN mappings in ELF notes

This commit is contained in:
Ehmry - 2022-10-07 18:01:25 -05:00
parent 256fac99ad
commit d2bf5375d8
9 changed files with 310 additions and 302 deletions

View File

@ -3,14 +3,16 @@
"eris": { "eris": {
"inputs": { "inputs": {
"nimble": "nimble", "nimble": "nimble",
"nixpkgs": "nixpkgs_2" "nixpkgs": [
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1652741572, "lastModified": 1665183375,
"narHash": "sha256-c+8/yxYckS2PrA7SoEmEr6dqDwzQnw1Hz2LhJBDN4DA=", "narHash": "sha256-soRRiLo2fGGiup7vK3nKUQ7rvJQWt1d941uD+wGT2Oc=",
"ref": "master", "ref": "refs/heads/trunk",
"rev": "27bd39452ec548744e14a3169e85602340125851", "rev": "c190cc13e5f2518913a266180a26b54d39dbcc87",
"revCount": 10, "revCount": 30,
"type": "git", "type": "git",
"url": "https://codeberg.org/eris/nix-eris" "url": "https://codeberg.org/eris/nix-eris"
}, },
@ -21,31 +23,17 @@
}, },
"nimble": { "nimble": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs" "nixpkgs": [
"eris",
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1652579357, "lastModified": 1662949370,
"narHash": "sha256-hy50WWc872o177Ok4GQoMOi3La2DlzJyEboOD4iGE8Q=", "narHash": "sha256-tNGaNy/0iOS54wYK7g7AQIpArMg8XqCQsAisoZ7Dg4U=",
"owner": "nix-community", "owner": "nix-community",
"repo": "flake-nimble", "repo": "flake-nimble",
"rev": "a48df7c801b1da371492f5689dfbd5f6a128a6c2", "rev": "54dd3e91c0b61ea63eb4065f95b97f3f0fc98b06",
"type": "github"
},
"original": {
"id": "nimble",
"type": "indirect"
}
},
"nimble_2": {
"inputs": {
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1652924471,
"narHash": "sha256-8lxEUhy5XXLaMy8J8eWwiufHUZpTnrI4ykS5lekPq3Y=",
"owner": "nix-community",
"repo": "flake-nimble",
"rev": "c3993134d3d8e6a601311fb662b2698b26b43575",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -55,53 +43,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1641555862, "lastModified": 1665079737,
"narHash": "sha256-AJK1Q5djPXs/ba3K6gHsVAer9yDPVLic78ZIDsFSkHU=", "narHash": "sha256-mbi/+D73l2VXmiIJzh1oNjohrh+o2MrPblEGzaR7IiI=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "d1acd89e0116ff88eba80541027429fc922612e9",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1652692103,
"narHash": "sha256-ygRLh8g0F/WkVCSfQcxMoVaaD45i6Ky+f+b4wCOazag=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "556ce9a40abde33738e6c9eac65f965a8be3b623",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1641555862,
"narHash": "sha256-AJK1Q5djPXs/ba3K6gHsVAer9yDPVLic78ZIDsFSkHU=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "d1acd89e0116ff88eba80541027429fc922612e9",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_4": {
"locked": {
"lastModified": 1653521725,
"narHash": "sha256-JO3Ni/gV4+7eloZrXW0hY7PNfy5TGVJWOPEhtnV9ugQ=",
"owner": "ehmry", "owner": "ehmry",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "2ec153670397dd3393e6b79d3057c0279539eb10", "rev": "f971220848e4f9efe39667bc986f10e378a8b877",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -114,8 +60,11 @@
"root": { "root": {
"inputs": { "inputs": {
"eris": "eris", "eris": "eris",
"nimble": "nimble_2", "nimble": [
"nixpkgs": "nixpkgs_4" "eris",
"nimble"
],
"nixpkgs": "nixpkgs"
} }
} }
}, },

View File

@ -2,7 +2,11 @@
description = "Nix flavored Genode distribution"; description = "Nix flavored Genode distribution";
inputs = { inputs = {
eris.url = "git+https://codeberg.org/eris/nix-eris"; eris = {
url = "git+https://codeberg.org/eris/nix-eris";
inputs.nixpkgs.follows = "nixpkgs";
};
nimble.follows = "eris/nimble";
nixpkgs.url = "github:ehmry/nixpkgs/sigil-21.11"; nixpkgs.url = "github:ehmry/nixpkgs/sigil-21.11";
}; };
@ -55,7 +59,7 @@
# Overlay of adjustments applied to Nixpkgs as well as # Overlay of adjustments applied to Nixpkgs as well as
# the "genodePackages" set which the "packages" # the "genodePackages" set which the "packages"
# output of this flake is taken. # output of this flake is taken.
import ./overlay { flake = self; }; import ./overlay;
lib = lib =
# Local utilities merged with the Nixpkgs lib # Local utilities merged with the Nixpkgs lib

View File

@ -1,4 +1,3 @@
{ flake }:
final: prev: final: prev:
with prev; with prev;
@ -99,6 +98,8 @@ in nullPkgs // {
# The Genode-only packages. # The Genode-only packages.
import ../packages { inherit final prev; }; import ../packages { inherit final prev; };
getdns = overrideHost { doxygen = null; } prev.getdns;
grub2 = grub2 =
# No need for a Genode build of GRUB. # No need for a Genode build of GRUB.
if stdenv.targetPlatform.isGenode then if stdenv.targetPlatform.isGenode then
@ -168,14 +169,15 @@ in nullPkgs // {
# Packages from the Nimble flake with adjustments. # Packages from the Nimble flake with adjustments.
prev.nimPackages.overrideScope' (_: prev': { prev.nimPackages.overrideScope' (_: prev': {
dhall = with prev'; buildNimPackage rec { dhall = with prev';
name = "dhall"; buildNimPackage rec {
version = "0.1.0"; pname = "dhall";
version = "20221007";
src = prev.fetchFromSourcehut { src = prev.fetchFromSourcehut {
owner = "~ehmry"; owner = "~ehmry";
repo = "dhall-nim"; repo = "${pname}-nim";
rev = version; rev = version;
hash = "sha256-AhGD/h61Yqiq80woD8bfrvwuTjqCPGYCmUFhK5xFur4="; hash = "sha256-wDD9ZRQ6FcQrPLFMCFJcsBIXFzE3wLYqL12AF1KPE0g=";
}; };
buildInputs = [ bigints cbor ]; buildInputs = [ bigints cbor ];
}; };

View File

@ -1,9 +1,10 @@
{ buildNimPackage, patchelf, base32, bigints, cbor, dhall, eris }: { lib, buildNimPackage, bintools-unwrapped, patchelf, base32, bigints, cbor, dhall, eris }:
buildNimPackage { buildNimPackage {
name = "eris_patch"; name = "eris_patch";
buildInputs = [ base32 bigints cbor dhall eris ]; buildInputs = [ base32 bigints cbor dhall eris ];
inherit patchelf; patchelf = "${lib.getBin patchelf}/bin/patchelf";
objcopy = "${lib.getBin bintools-unwrapped}/bin/objcopy";
unpackPhase = "install -D ${./eris_patch.nim} ./src/eris_patch.nim"; unpackPhase = "install -D ${./eris_patch.nim} ./src/eris_patch.nim";
nimBinOnly = true; nimBinOnly = true;
preConfigure = '' preConfigure = ''

View File

@ -1,6 +1,29 @@
import std/[asyncdispatch, deques, json, os, osproc, streams, strutils, tables] import std/[asyncdispatch, deques, json, os, osproc, streams, strutils, tables]
import dhall/[render, terms] import cbor, dhall/[render, terms], eris
import eris
const selfDescribedCbor = 55799
proc writeErisLinks(path: string; node: CborNode) =
# Inspired by "Package Metadata for Core Files"
# - https://systemd.io/COREDUMP_PACKAGE_METADATA/
# - http://netbsd.org/docs/kernel/elf-notes.html
const name = "Sigil\x00"
var links = newStringStream()
links.writeCborTag(selfDescribedCbor)
links.writeCbor(node)
var file = openFileStream(path, fmWrite)
file.write(uint32 name.len)
file.write(uint32 links.data.len)
file.write(uint32 1)
file.write(name)
while (file.getPosition and 3) != 0: file.write(byte 0)
file.write(links.data)
while (file.getPosition and 3) != 0: file.write(byte 0)
close(file)
proc toCbor(cap: ErisCap): CborNode =
result = initCborBytes(cap.bytes)
result.tag = erisCborTag
proc toDhall(js: JsonNode): Value = proc toDhall(js: JsonNode): Value =
case js.kind case js.kind
@ -13,14 +36,6 @@ proc toDhall(js: JsonNode): Value =
else: else:
raiseAssert "unhandled JSON value" raiseAssert "unhandled JSON value"
if getEnv("dontErisPatch") != "": quit 0
let
patchelf = getEnv("ERIS_PATCHELF", "patchelf")
nixStore = getEnv("NIX_STORE", "/nix/store")
jsonManifestSubPath = "nix-support" / "eris-manifest.json"
dhallManifestSubPath = "nix-support" / "eris-manifest.dhall"
proc isElf(path: string): bool = proc isElf(path: string): bool =
var magic: array[4, char] var magic: array[4, char]
let file = open(path) let file = open(path)
@ -28,24 +43,46 @@ proc isElf(path: string): bool =
close(file) close(file)
magic == [0x7f.char, 'E', 'L', 'F'] magic == [0x7f.char, 'E', 'L', 'F']
type PendingFile = ref object proc main =
var generateManifests, generateNotes, addNotes, runPatchelf: bool
for arg in commandLineParams():
case arg
of "--add-notes": addNotes = true
of "--run-patchelf": runPatchelf = true
of "--generate-manifests": generateManifests = true
of "--generate-notes": generateNotes = true
if getEnv("dontErisPatch") != "": quit 0
let
patchelf = getEnv("ERIS_PATCHELF", "patchelf")
objcopy = getEnv("ERIS_OBJCOPY", "objcopy")
nixStore = getEnv("NIX_STORE", "/nix/store")
jsonManifestSubPath = "nix-support" / "eris-manifest.json"
dhallManifestSubPath = "nix-support" / "eris-manifest.dhall"
type PendingFile = ref object
outputRoot, filePath: string outputRoot, filePath: string
replacements: Table[string, string] replacements: Table[string, string]
erisLinks: CborNode
var var
outputManifests = initTable[string, JsonNode]() outputManifests = initTable[string, JsonNode]()
pendingFiles = initDeque[PendingFile]() pendingFiles = initDeque[PendingFile]()
failed = false failed = false
for outputName in getEnv("outputs").splitWhitespace: if getEnv("outputs") == "":
quit """package $outputs not set in environment"""
for outputName in getEnv("outputs").splitWhitespace:
if getEnv(outputName) == "":
quit("package $" & outputName & " not set in environment")
let outputRoot = getEnv(outputName) let outputRoot = getEnv(outputName)
if fileExists(outputRoot / jsonManifestSubPath): if fileExists(outputRoot / jsonManifestSubPath):
echo "Not running ERIS patch hook again" stderr.writeLine "Not running ERIS patch hook again"
quit 0 quit 0
outputManifests[outputRoot] = newJObject() outputManifests[outputRoot] = newJObject()
let buildInputs = getEnv("buildInputs").splitWhitespace let buildInputs = getEnv("buildInputs").splitWhitespace
proc resolveNeed(rpath: seq[string]; need: string): string = proc resolveNeed(rpath: seq[string]; need: string): string =
if need.isAbsolute: if need.isAbsolute:
return need return need
for libdir in rpath: for libdir in rpath:
@ -63,11 +100,12 @@ proc resolveNeed(rpath: seq[string]; need: string): string =
if fileExists(absNeed): if fileExists(absNeed):
return absNeed return absNeed
proc resolveFile(outputRoot, filePath: string): PendingFile = proc resolveFile(outputRoot, filePath: string): PendingFile =
result = PendingFile( result = PendingFile(
outputRoot: outputRoot, outputRoot: outputRoot,
filePath: filePath, filePath: filePath,
replacements: initTable[string, string](8)) replacements: initTable[string, string](8),
erisLinks: initCborMap())
let needs = splitWhitespace(execProcess( let needs = splitWhitespace(execProcess(
patchelf, args = ["--print-needed", filePath], options = {poUsePath})) patchelf, args = ["--print-needed", filePath], options = {poUsePath}))
let rpath = splitWhitespace(execProcess( let rpath = splitWhitespace(execProcess(
@ -76,37 +114,31 @@ proc resolveFile(outputRoot, filePath: string): PendingFile =
if need == "ld.lib.so" or need.startsWith("urn:"): continue if need == "ld.lib.so" or need.startsWith("urn:"): continue
result.replacements[need] = resolveNeed(rpath, need) result.replacements[need] = resolveNeed(rpath, need)
var capCache = initTable[string, ErisCap]() var capCache = initTable[string, ErisCap]()
proc fileUrn(filePath: string): string = proc fileCap(filePath: string): ErisCap =
## Determine the ERIS URN for ``filePath``. ## Determine the ERIS read capabililty for ``filePath``.
var cap: ErisCap
if capCache.hasKey(filePath): if capCache.hasKey(filePath):
cap = capCache[filePath] result = capCache[filePath]
else: else:
try: try:
let blockSize = if getFileSize(filePath) < (16 shl 10):
bs1k
else:
bs32k
let str = openFileStream(filePath) let str = openFileStream(filePath)
cap = waitFor encode(newDiscardStore(), blockSize, str) result = waitFor encode(newDiscardStore(), str, convergentMode)
capCache["filePath"] = cap capCache["filePath"] = result
close(str) close(str)
except: except:
stderr.writeLine("failed to read \"", filePath, "\"") stderr.writeLine("failed to read \"", filePath, "\"")
quit 1 quit 1
$cap # & "#" & encodeUrl(extractFilename(filePath), usePlus = false)
var closureCache = initTable[string, TableRef[string, string]]() var closureCache = initTable[string, TableRef[string, ErisCap]]()
proc fileClosure(filePath: string): TableRef[string, string] = proc fileClosure(filePath: string): TableRef[string, ErisCap] =
## Recusively find the dependency closure of ``filePath``. ## Recusively find the dependency closure of ``filePath``.
let filePath = expandFilename filePath let filePath = expandFilename filePath
if closureCache.hasKey(filePath): if closureCache.hasKey(filePath):
result = closureCache[filePath] result = closureCache[filePath]
else: else:
result = newTable[string, string]() result = newTable[string, ErisCap]()
var storePath = filePath var storePath = filePath
for p in parentDirs(filePath): for p in parentDirs(filePath):
# find the top directory of the ``filePath`` derivation # find the top directory of the ``filePath`` derivation
@ -119,15 +151,15 @@ proc fileClosure(filePath: string): TableRef[string, string] =
let let
manifest = parseFile(manifestPath) manifest = parseFile(manifestPath)
entry = manifest[filePath.extractFilename] entry = manifest[filePath.extractFilename]
for path, cap in entry["closure"].pairs: for path, urn in entry["closure"].pairs:
result[path] = cap.getStr result[path] = parseErisUrn urn.getStr
let otherClosure = fileClosure(path) let otherClosure = fileClosure(path)
for otherPath, otherCap in otherClosure.pairs: for otherPath, otherCap in otherClosure.pairs:
# merge the closure of the dependency # merge the closure of the dependency
result[otherPath] = otherCap result[otherPath] = otherCap
closureCache[filePath] = result closureCache[filePath] = result
for outputRoot in outputManifests.keys: for outputRoot in outputManifests.keys:
let manifestPath = outputRoot / jsonManifestSubPath let manifestPath = outputRoot / jsonManifestSubPath
if fileExists manifestPath: continue if fileExists manifestPath: continue
for filePath in walkDirRec(outputRoot, relative = false): for filePath in walkDirRec(outputRoot, relative = false):
@ -135,11 +167,11 @@ for outputRoot in outputManifests.keys:
if filePath.isElf: if filePath.isElf:
pendingFiles.addLast(resolveFile(outputRoot, filePath)) pendingFiles.addLast(resolveFile(outputRoot, filePath))
var var
prevLen = pendingFiles.len prevLen = pendingFiles.len
prevPrevLen = prevLen.succ prevPrevLen = prevLen.succ
# used to detect reference cycles # used to detect reference cycles
while pendingFiles.len != 0: while pendingFiles.len != 0:
block selfReferenceCheck: block selfReferenceCheck:
# process the files that have been collected # process the files that have been collected
# taking care not to take a the URN of an # taking care not to take a the URN of an
@ -150,17 +182,17 @@ while pendingFiles.len != 0:
for need, replacementPath in pendingFile.replacements.pairs: for need, replacementPath in pendingFile.replacements.pairs:
# search for self-references # search for self-references
if replacementPath == "": if replacementPath == "":
echo need, " not found for ", filePath stderr.writeLine need, " not found for ", filePath
failed = true failed = true
continue continue
for outputRoot in outputManifests.keys: for outputRoot in outputManifests.keys:
if replacementPath.startsWith(outputRoot): if replacementPath.startsWith(outputRoot):
for other in pendingFiles.items: for other in pendingFiles.items:
echo "compare for self-reference:" stderr.writeLine "compare for self-reference:"
echo '\t', replacementPath stderr.writeLine '\t', replacementPath
echo '\t', other.filePath stderr.writeLine '\t', other.filePath
if replacementPath == other.filePath: if replacementPath == other.filePath:
echo "defering patch of ", filePath, " with reference to ", other.filePath stderr.writeLine "defering patch of ", filePath, " with reference to ", other.filePath
pendingFiles.addLast(pendingFile) pendingFiles.addLast(pendingFile)
break selfReferenceCheck break selfReferenceCheck
var var
@ -168,36 +200,67 @@ while pendingFiles.len != 0:
replaceCmd = patchelf & " --set-rpath '' " & filePath replaceCmd = patchelf & " --set-rpath '' " & filePath
for need, replacementPath in pendingFile.replacements.pairs: for need, replacementPath in pendingFile.replacements.pairs:
if replacementPath == "": continue if replacementPath == "": continue
let urn = fileUrn(replacementPath) let
echo "replace reference to ", need, " with ", urn cap = fileCap(replacementPath)
replaceCmd.add(" --replace-needed $# $#" % [need, urn]) urn = $cap
stderr.writeLine "replace reference to ", need, " with ", urn
closure[replacementPath] = %urn closure[replacementPath] = %urn
for path, urn in fileClosure(replacementPath).pairs: pendingFile.erisLinks[ replacementPath.toCbor] = cap.toCbor
closure[path] = %urn replaceCmd.add(" --replace-needed $# $#" % [need, urn])
if pendingFile.replacements.len != 0: for path, cap in fileClosure(replacementPath).pairs:
closure[path] = %($cap)
pendingFile.erisLinks[path.toCbor] = cap.toCbor
if runPatchelf and pendingFile.replacements.len != 0:
let exitCode = execCmd(replaceCmd) let exitCode = execCmd(replaceCmd)
if exitCode != 0: if exitCode != 0:
echo "Patchelf failed - ", replaceCmd stderr.writeLine "Patchelf failed - ", replaceCmd
quit exitCode quit exitCode
let notePath = getEnv("TMPDIR", ".") / "eris-links.note"
if generateNotes or addNotes:
if generateNotes:
stderr.writeLine("writing .notes.eris-links section to ", notePath)
sort(pendingFile.erisLinks)
writeErisLinks(notePath, pendingFile.erisLinks)
if addNotes:
# Modify the file with objcopy last because binutils surely
# has a more conventional interpretation of the ELF standard
# than patchelf.
let tmpFile = pendingFile.filePath & ".with-note"
let objcopyCommand = [
objcopy,
"--add-section .note.eris-links=" & notePath,
"--set-section-flags .note.eris-links=noload,readonly",
pendingFile.filePath, tmpfile]
let exitCode = execCmd(objcopyCommand.join(" "))
if exitCode != 0:
quit("Adding note to $1 failed" % pendingFile.filePath)
moveFile(tmpFile, pendingFile.filePath)
outputManifests[pendingFile.outputRoot][filePath.extractFilename] = %* { outputManifests[pendingFile.outputRoot][filePath.extractFilename] = %* {
"cap": fileUrn(filePath), "cap": $fileCap(filePath),
"closure": closure, "closure": closure,
"path": filePath "path": filePath
} }
if pendingFiles.len == prevPrevLen: if pendingFiles.len == prevPrevLen:
failed = true failed = true
echo "reference cycle detected in the following:" stderr.writeLine "reference cycle detected in the following:"
for remain in pendingFiles.items: for remain in pendingFiles.items:
echo '\t', " ", remain.filePath stderr.writeLine '\t', " ", remain.filePath
break break
prevPrevLen = prevLen prevPrevLen = prevLen
prevLen = pendingFiles.len prevLen = pendingFiles.len
if failed: if failed:
quit -1 quit -1
for outputRoot, manifest in outputManifests: if generateManifests:
for outputRoot, manifest in outputManifests:
let supportDir = outputRoot / "nix-support" let supportDir = outputRoot / "nix-support"
createDir(supportDir) createDir(supportDir)
writeFile(outputRoot / jsonManifestSubPath, $manifest) writeFile(outputRoot / jsonManifestSubPath, $manifest)
writeFile(outputRoot / dhallManifestSubPath, $(manifest.toDhall)) writeFile(outputRoot / dhallManifestSubPath, $(manifest.toDhall))
main()

View File

@ -1,2 +1,3 @@
export ERIS_PATCHELF=@patchelf@/bin/patchelf export ERIS_PATCHELF=@patchelf@
postFixupHooks+=('@out@/bin/eris_patch') export ERIS_OBJCOPY=@objcopy@
postFixupHooks+=('@out@/bin/eris_patch --add-notes --generate-manifests --run-patchelf')

View File

@ -24,13 +24,13 @@ let
''; '';
}); });
in upstream // { in upstream // (with final; {
bender = buildPackages.callPackage ./bender { }; bender = buildPackages.callPackage ./bender { };
block_router = callPackage ./block_router { }; block_router = callPackage ./block_router { };
device_manager = callPackage ./device_manager { }; device_manager = nimPackages.callPackage ./device_manager { };
dhallSigil = dhallPackages.sigil; dhallSigil = dhallPackages.sigil;
@ -59,4 +59,4 @@ in upstream // {
sha256 = "0dy906ffbw6khkwd05vhppcw2mr4ma0h3b6n52a71cfail87jfnw"; sha256 = "0dy906ffbw6khkwd05vhppcw2mr4ma0h3b6n52a71cfail87jfnw";
}; };
} })

View File

@ -1,33 +1,26 @@
{ lib, stdenv, fetchgit, nim, nimblePackages }: { lib, buildNimPackage, fetchFromSourcehut, genode }:
stdenv.mkDerivation rec { buildNimPackage rec {
pname = "device_manager"; pname = "device_manager";
version = "0.0"; version = "0.0";
outputs = [ "out" "dhall" ]; outputs = [ "out" "dhall" ];
src = fetchgit { src = fetchFromSourcehut {
url = "https://git.sr.ht/~ehmry/${pname}"; owner = "~ehmry";
repo = pname;
rev = "4ff7d47b83255a437d862d16b8424a3c05e3eab1"; rev = "4ff7d47b83255a437d862d16b8424a3c05e3eab1";
sha256 = "0bmcl693w34ayrw77c6gicph43yfjfm800jwj57ryshr9fdh88dq"; hash = "sha256-uCEEm0sZap9PkVwCgKqTzg8CL4vPsHN49ooMPpKhrC4=";
}; };
nimFlags = with nimblePackages; preConfigure = ''
map (lib: "--path:${lib}/src") [ genode ] ++ [ "-d:posix" ]; echo 'backend = "cpp"' >> ${pname}.nimble
nativeBuildInputs = [ nim ];
preHook = ''
export HOME="$NIX_BUILD_TOP"
''; '';
buildPhase = '' nimDefines = [ "posix" ];
runHook preBuild
nim cpp $nimFlags src/$pname
runHook postBuild
'';
installPhase = '' buildInputs = [ genode ];
install -Dt $out/bin src/$pname
postInstall = ''
install -Dt $dhall config/package.dhall install -Dt $dhall config/package.dhall
''; '';
} }

View File

@ -3,23 +3,18 @@
machine = { pkgs, ... }: { machine = { pkgs, ... }: {
genode.init.children.test_nim = let genode.init.children.test_nim = let
testNim = with pkgs; testNim = with pkgs;
stdenv.mkDerivation { nimPackages.buildNimPackage {
pname = "test-nim"; pname = "test_nim";
inherit (nim-unwrapped) version; inherit (nim) version;
nativeBuildInputs = [ nim ]; nimDefines = [ "posix" ];
dontUnpack = true; unpackPhase = ''
dontConfigure = true; mkdir test
buildPhase = '' cd test
export HOME=$NIX_BUILD_TOP echo 'echo "Hello Nim world!"' > test_nim.nim
cat << EOF > test_nim.nim cat << EOF > eris_patch.nimble
echo "Hello Nim world!" backend = "cpp"
bin = @[ "test_nim"]
EOF EOF
nim cpp -d:posix -d:release --gc:orc test_nim
'';
installPhase = ''
install -Dt $out/bin test_nim
''; '';
}; };
in { in {