@@ -46,11 +46,11 @@ rec {
4646 } ;
4747
4848 # Description: read opam files from mirage configuration
49- # and build a unikernel in a separate output
50- # for each one of the given targets.
49+ # and build a unikernel for the given target.
5150 build = lib . extendMkDerivation {
5251 constructDrv = stdenv . mkDerivation ;
5352 excludeDrvArgNames = [
53+ "target"
5454 "materializedDir"
5555 "monorepoQuery"
5656 "overrideUnikernel"
6262 {
6363 pname ,
6464 version ,
65- targets ,
6665 src ,
66+ target ,
6767 monorepoQuery ,
6868 materializedDir ,
6969 mirageDir ? "." ,
@@ -74,25 +74,14 @@ rec {
7474 } @args :
7575 let
7676 name = "mirage-${ pname } " ;
77- mirageConfIFD = configure args ;
78- mirageConf =
79- target :
80- configure (
81- args
82- // {
83- opamPackages = packages target ;
84- }
85- ) target ;
86- packagesMaterialized =
87- target : opam-nix . materializeOpamProject { } "${ name } -${ target } " ( mirageConfIFD target ) query ;
88- monorepoMaterialized =
89- target : opam-nix . materializeBuildOpamMonorepo { } ( mirageConfIFD target ) monorepoQuery ;
90- monorepo =
91- target : opam-nix . unmaterializeQueryToMonorepo { } ( materializedDir + "/${ target } /monorepo.json" ) ;
77+ mirageConfIFD = configure args target ;
78+ mirageConf = configure ( args // { opamPackages = packages ; } ) target ;
79+ packagesMaterialized = opam-nix . materializeOpamProject { } "${ name } -${ target } " mirageConfIFD query ;
80+ monorepoMaterialized = opam-nix . materializeBuildOpamMonorepo { } mirageConfIFD monorepoQuery ;
81+ monorepo = opam-nix . unmaterializeQueryToMonorepo { } ( materializedDir + "/${ target } /monorepo.json" ) ;
9282 packages =
93- target :
9483 ( opam-nix . materializedDefsToScope {
95- sourceMap . "${ name } -${ target } " = finalAttrs . passthru . mirageConf . ${ target } ;
84+ sourceMap . "${ name } -${ target } " = finalAttrs . passthru . mirageConf ;
9685 } ( materializedDir + "/${ target } /packages.json" ) ) . overrideScope
9786 (
9887 finalOpam : previousOpam : {
@@ -113,7 +102,7 @@ rec {
113102 echo '(vendored_dirs *)' > duniverse/dune
114103 ${ lib . concatStringsSep "\n " (
115104 lib . mapAttrsToList ( name : path : "cp -r ${ path } duniverse/${ lib . toLower name } " ) (
116- finalAttrs . passthru . monorepo . ${ target }
105+ finalAttrs . passthru . monorepo
117106 )
118107 ) }
119108 dune build ${ mirageDir } --profile release
@@ -139,25 +128,24 @@ rec {
139128 {
140129 inherit name ;
141130 inherit src ;
142- outputs = [ "out" ] ++ targets ;
143131 installPhase = ''
144132 runHook preInstall
145- ${
146- if stdenv . hostPlatform . isLinux && lib . elem "unix" targets then
147- "ln -s $unix $out"
148- else if stdenv . hostPlatform . isDarwin && lib . elem "macosx" targets then
149- "ln -s $macosx $out"
150- else
151- "mkdir $out"
133+ cp -R --no-preserve=mode ${ finalAttrs . passthru . packages . "${ name } -${ target } " } $out
134+ ${ lib . optionalString
135+ (
136+ ( stdenv . hostPlatform . isLinux && target == "unix" )
137+ || ( stdenv . hostPlatform . isDarwin && target == "macosx" )
138+ )
139+ ''
140+ install -Dm755 $out/share/mirageos/${ pname } $out/bin/${ pname }
141+ rm -rf $out/share
142+ ''
152143 }
153- ${ lib . concatMapStringsSep "\n " ( target : ''
154- cp -R ${ finalAttrs . passthru . packages . ${ target } . "${ name } -${ target } " } '' $${ target }
155- '' ) targets }
156144 runHook postInstall
157145 '' ;
158146 passthru = {
159147 updateScript = writeShellApplication {
160- name = "dnsvizor-update" ;
148+ name = "dnsvizor-update- ${ target } " ;
161149 runtimeInputs = [
162150 coreutils
163151 jq
@@ -166,28 +154,61 @@ rec {
166154 text = ''
167155 set -x
168156 materializedDir=$(nix --extra-experimental-features nix-command -L eval \
169- -f. ${ pname } .passthru.materializedDir)
170- ''
171- + lib . concatMapStringsSep "\n " ( target : ''
172- mkdir -p "${ materializedDir } /${ target } /"
157+ -f. ${ pname } .passthru.${ target } .passthru.materializedDir)
158+ mkdir -p "$materializedDir/${ target } /"
173159 packagesJson=$(nix --extra-experimental-features nix-command -L build \
174160 --no-link --print-out-paths --allow-import-from-derivation --show-trace \
175- -f. ${ pname } .passthru.packagesMaterialized. ${ target } )
176- jq <"$packagesJson" >"'' ${ materializedDir} /${ target } /packages.json"
161+ -f. ${ pname } .passthru.${ target } .passthru.packagesMaterialized )
162+ jq <"$packagesJson" >"$ materializedDir/${ target } /packages.json"
177163 monorepoJson=$(nix --extra-experimental-features nix-command -L build \
178164 --no-link --print-out-paths --allow-import-from-derivation --show-trace \
179- -f. ${ pname } .passthru.monorepoMaterialized.${ target } )
180- jq <"$monorepoJson" >"'' ${materializedDir}/${ target } /monorepo.json"
165+ -f. ${ pname } .passthru.${ target } .passthru.monorepoMaterialized)
166+ jq <"$monorepoJson" >"$materializedDir/${ target } /monorepo.json"
167+ '' ;
168+ } ;
169+ inherit
170+ materializedDir
171+ mirageConf
172+ mirageConfIFD
173+ monorepo
174+ monorepoMaterialized
175+ packages
176+ packagesMaterialized
177+ ;
178+ } ;
179+ } ;
180+ } ;
181+
182+ builds = lib . extendMkDerivation {
183+ constructDrv = stdenv . mkDerivation ;
184+ excludeDrvArgNames = [
185+ "target"
186+ "materializedDir"
187+ "monorepoQuery"
188+ "overrideUnikernel"
189+ "query"
190+ "queryArgs"
191+ ] ;
192+ extendDrvArgs =
193+ finalAttrs :
194+ {
195+ targets ? finalAttrs . targets or possibleTargets ,
196+ ...
197+ } @args :
198+ {
199+ passthru = lib . genAttrs targets ( target : build ( args // { inherit target ; } ) ) // {
200+ updateScript = writeShellApplication {
201+ name = "dnsvizor-update" ;
202+ text = lib . concatMapStringsSep "\n " ( target : ''
203+ ${ lib . getExe finalAttrs . passthru . ${ target } . passthru . updateScript }
181204 '' ) targets ;
182205 } ;
183- mirageConfIFD = lib . genAttrs targets mirageConfIFD ;
184- mirageConf = lib . genAttrs targets mirageConf ;
185- monorepoMaterialized = lib . genAttrs targets monorepoMaterialized ;
186- packagesMaterialized = lib . genAttrs targets packagesMaterialized ;
187- packages = lib . genAttrs targets packages ;
188- monorepo = lib . genAttrs targets monorepo ;
189- inherit materializedDir ;
190206 } ;
207+ installPhase = ''
208+ runHook preInstall
209+ mkdir -p $out
210+ runHook postInstall
211+ '' ;
191212 } ;
192213 } ;
193214
0 commit comments