2
0
Fork 0

Restructure flake.nix to use a nixpkgs overlay

This commit is contained in:
Emery Hemingway 2020-03-21 21:38:37 +05:30
parent d1f2ea427e
commit a0a31fa548
7 changed files with 104 additions and 92 deletions

183
flake.nix
View File

@ -13,77 +13,12 @@
outputs = { self, genode-depot, nixpkgs, nixpkgsUpstream }: outputs = { self, genode-depot, nixpkgs, nixpkgsUpstream }:
let let
mkOutput = { system, localSystem, crossSystem }:
let thisSystem = builtins.getAttr system;
in rec {
lib = (nixpkgs.lib) // (import ./lib {
inherit system localSystem crossSystem;
inherit apps nixpkgs genode-depot;
genodepkgs = self;
});
legacyPackages = thisSystem nixpkgs.legacyPackages;
# pass thru Nixpkgs
packages = import ./packages {
inherit system legacyPackages apps;
localPackages = nixpkgsUpstream.legacyPackages.${localSystem};
depot = thisSystem genode-depot.packages;
};
devShell = let
pkgs = nixpkgsUpstream.legacyPackages.x86_64-linux;
fhs = pkgs.buildFHSUserEnv {
name = "genode-env";
targetPkgs = pkgs:
(with pkgs; [
binutils
bison
expect
flex
git
glibc.dev
gnumake
libxml2
qemu
tcl
which
xorriso
]);
runScript = "bash";
extraBuildCommands = let
toolchain = pkgs.fetchzip {
url = "file:///" + packages.genodeSources.toolchain.src;
hash = "sha256-26rPvLUPEJm40zLSqTquwuFTJ1idTB0T4VXgaHRN+4o=";
};
in "ln -s ${toolchain}/local usr/local";
};
in pkgs.stdenv.mkDerivation {
name = "genode-fhs-shell";
nativeBuildInputs = [ fhs ];
shellHook = "exec genode-env";
};
apps = import ./apps {
self = self.apps.${localSystem};
nixpkgs = legacyPackages;
nixpkgsLocal = nixpkgsUpstream.legacyPackages.${localSystem};
inherit packages;
};
checks = import ./tests {
inherit system localSystem crossSystem;
inherit self nixpkgs genode-depot;
inherit apps lib;
genodepkgs = thisSystem self.packages;
};
};
localSystems = [ "x86_64-linux" ]; localSystems = [ "x86_64-linux" ];
crossSystems = [ "x86_64-genode" ]; crossSystems = [ "x86_64-genode" ];
forAllLocalSystems = f:
nixpkgs.lib.genAttrs localSystems (system: f system);
forAllCrossSystems = f: forAllCrossSystems = f:
with builtins; with builtins;
let let
@ -97,26 +32,102 @@
attrSet = listToAttrs list; attrSet = listToAttrs list;
in attrSet; in attrSet;
finalize = outputs: forAllSystems = f:
with builtins; (forAllCrossSystems f) // (forAllLocalSystems (system:
f {
inherit system;
localSystem = system;
crossSystem = system;
}));
nixpkgsFor = forAllSystems ({ system, localSystem, crossSystem }:
if localSystem == crossSystem then
import nixpkgsUpstream {
inherit system;
overlays = [ self.overlay ];
}
else
import nixpkgs {
inherit localSystem crossSystem;
config.allowUnsupportedSystem = true;
overlays = [ self.overlay ];
});
in rec {
overlay = import ./overlay;
lib = forAllCrossSystems ({ system, localSystem, crossSystem }:
(nixpkgs.lib) // (import ./lib {
inherit system localSystem crossSystem;
apps = self.apps.${system};
nixpkgs = nixpkgsFor.${system};
genode-depot = genode-depot.packages.${system};
genodepkgs = self;
}));
legacyPackages = forAllSystems
({ system, localSystem, crossSystem }: nixpkgsFor.${system});
# pass thru Nixpkgs
packages = forAllCrossSystems ({ system, localSystem, crossSystem }:
import ./packages {
inherit system;
legacyPackages = self.legacyPackages.${system};
apps = self.apps.${system};
localPackages = nixpkgsUpstream.legacyPackages.${localSystem};
depot = genode-depot.packages.${system};
});
devShell = forAllLocalSystems (system:
let let
outputs' = outputs // { pkgs = nixpkgsFor.${system};
x86_64-linux = getAttr "x86_64-linux-x86_64-genode" outputs; fhs = pkgs.buildFHSUserEnv {
name = "genode-env";
targetPkgs = pkgs:
(with pkgs; [
binutils
bison
expect
flex
git
glibc.dev
gnumake
libxml2
qemu
tcl
which
xorriso
]);
runScript = "bash";
extraBuildCommands = let
toolchain = pkgs.fetchzip {
url = "file://${packages.x86_64-linux-x86_64-genode.genodeSources.toolchain.src}";
hash = "sha256-26rPvLUPEJm40zLSqTquwuFTJ1idTB0T4VXgaHRN+4o=";
};
in "ln -s ${toolchain}/local usr/local";
}; };
systems = attrNames outputs'; in pkgs.stdenv.mkDerivation {
outputAttrs = attrNames (head (attrValues outputs')); name = "genode-fhs-shell";
nativeBuildInputs = [ fhs ];
shellHook = "exec genode-env";
});
list = map (attr: { apps = forAllCrossSystems ({ system, localSystem, crossSystem }:
name = attr; import ./apps {
value = listToAttrs (map (system: { self = self.apps.${system};
name = system; nixpkgs = self.legacyPackages.${system};
value = getAttr attr (getAttr system outputs'); nixpkgsLocal = nixpkgsFor.${localSystem};
}) systems); packages = self.packages.${system};
}) outputAttrs; });
in listToAttrs list; checks = forAllCrossSystems ({ system, localSystem, crossSystem }:
import ./tests {
final = finalize (forAllCrossSystems mkOutput); inherit system localSystem crossSystem;
inherit self nixpkgs genode-depot;
in final; apps = self.apps.${system};
lib = self.lib.${system};
genodepkgs = self.packages.${system};
});
};
} }

View File

@ -22,7 +22,7 @@ in {
''; '';
mergeManifests = inputs: mergeManifests = inputs:
nixpkgs.legacyPackages.${localSystem}.writeTextFile { nixpkgs.writeTextFile {
name = "manifest.dhall"; name = "manifest.dhall";
text = with builtins; text = with builtins;
let let

3
overlay/default.nix Normal file
View File

@ -0,0 +1,3 @@
final: prev: {
}

View File

@ -33,9 +33,11 @@ let
"echo REPOSITORIES += ${genodeWorld} >> build/etc/build.conf"; "echo REPOSITORIES += ${genodeWorld} >> build/etc/build.conf";
}); });
genodeTupRules = ./Tuprules.tup;
in rec { in rec {
inherit (legacyPackages) stdenv; inherit (legacyPackages) stdenv;
inherit (genodeLabs) genodeSources; inherit (genodeLabs) genodeSources; # toolchain;
base-hw-pc = buildUpstream { base-hw-pc = buildUpstream {
name = "base-hw-pc"; name = "base-hw-pc";
@ -111,5 +113,4 @@ in rec {
sotest-producer = callPackage' ./sotest-producer { }; sotest-producer = callPackage' ./sotest-producer { };
stdcxx = callPackage' ./stdcxx { }; stdcxx = callPackage' ./stdcxx { };
} }

View File

@ -46,7 +46,6 @@ let
testConfig' = "${./test-wrapper.dhall} ${testConfig} (toMap ${manifest})"; testConfig' = "${./test-wrapper.dhall} ${testConfig} (toMap ${manifest})";
testEnv' = { testEnv' = {
DHALL_GENODE = "${testPkgs.dhallGenode}/source.dhall"; DHALL_GENODE = "${testPkgs.dhallGenode}/source.dhall";
MANIFEST = manifest;
XDG_CACHE_HOME = "/tmp"; XDG_CACHE_HOME = "/tmp";
} // testEnv; } // testEnv;

View File

@ -43,7 +43,6 @@ let
testConfig' = "${./test-wrapper.dhall} ${testConfig} (toMap ${manifest})"; testConfig' = "${./test-wrapper.dhall} ${testConfig} (toMap ${manifest})";
env' = { env' = {
DHALL_GENODE = "${testPkgs.dhallGenode}/source.dhall"; DHALL_GENODE = "${testPkgs.dhallGenode}/source.dhall";
MANIFEST = manifest;
XDG_CACHE_HOME = "/tmp"; XDG_CACHE_HOME = "/tmp";
} // env; } // env;

View File

@ -46,7 +46,6 @@ let
testConfig' = "${./test-wrapper.dhall} ${testConfig} (toMap ${manifest})"; testConfig' = "${./test-wrapper.dhall} ${testConfig} (toMap ${manifest})";
testEnv' = { testEnv' = {
DHALL_GENODE = "${testPkgs.dhallGenode}/source.dhall"; DHALL_GENODE = "${testPkgs.dhallGenode}/source.dhall";
MANIFEST = manifest;
XDG_CACHE_HOME = "/tmp"; XDG_CACHE_HOME = "/tmp";
} // testEnv; } // testEnv;