2
0
Fork 0

Restructure flake.nix to use a nixpkgs overlay

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

143
flake.nix
View File

@ -13,27 +13,75 @@
outputs = { self, genode-depot, nixpkgs, nixpkgsUpstream }: outputs = { self, genode-depot, nixpkgs, nixpkgsUpstream }:
let let
mkOutput = { system, localSystem, crossSystem }: localSystems = [ "x86_64-linux" ];
let thisSystem = builtins.getAttr system; crossSystems = [ "x86_64-genode" ];
in rec {
lib = (nixpkgs.lib) // (import ./lib { forAllLocalSystems = f:
inherit system localSystem crossSystem; nixpkgs.lib.genAttrs localSystems (system: f system);
inherit apps nixpkgs genode-depot;
genodepkgs = self; forAllCrossSystems = f:
with builtins;
let
f' = localSystem: crossSystem:
let system = localSystem + "-" + crossSystem;
in {
name = system;
value = f { inherit system localSystem crossSystem; };
};
list = nixpkgs.lib.lists.crossLists f' [ localSystems crossSystems ];
attrSet = listToAttrs list;
in attrSet;
forAllSystems = f:
(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 ];
}); });
legacyPackages = thisSystem nixpkgs.legacyPackages; 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 # pass thru Nixpkgs
packages = import ./packages { packages = forAllCrossSystems ({ system, localSystem, crossSystem }:
inherit system legacyPackages apps; import ./packages {
inherit system;
legacyPackages = self.legacyPackages.${system};
apps = self.apps.${system};
localPackages = nixpkgsUpstream.legacyPackages.${localSystem}; localPackages = nixpkgsUpstream.legacyPackages.${localSystem};
depot = thisSystem genode-depot.packages; depot = genode-depot.packages.${system};
}; });
devShell = let devShell = forAllLocalSystems (system:
pkgs = nixpkgsUpstream.legacyPackages.x86_64-linux; let
pkgs = nixpkgsFor.${system};
fhs = pkgs.buildFHSUserEnv { fhs = pkgs.buildFHSUserEnv {
name = "genode-env"; name = "genode-env";
targetPkgs = pkgs: targetPkgs = pkgs:
@ -54,7 +102,7 @@
runScript = "bash"; runScript = "bash";
extraBuildCommands = let extraBuildCommands = let
toolchain = pkgs.fetchzip { toolchain = pkgs.fetchzip {
url = "file:///" + packages.genodeSources.toolchain.src; url = "file://${packages.x86_64-linux-x86_64-genode.genodeSources.toolchain.src}";
hash = "sha256-26rPvLUPEJm40zLSqTquwuFTJ1idTB0T4VXgaHRN+4o="; hash = "sha256-26rPvLUPEJm40zLSqTquwuFTJ1idTB0T4VXgaHRN+4o=";
}; };
in "ln -s ${toolchain}/local usr/local"; in "ln -s ${toolchain}/local usr/local";
@ -63,60 +111,23 @@
name = "genode-fhs-shell"; name = "genode-fhs-shell";
nativeBuildInputs = [ fhs ]; nativeBuildInputs = [ fhs ];
shellHook = "exec genode-env"; shellHook = "exec genode-env";
}; });
apps = import ./apps { apps = forAllCrossSystems ({ system, localSystem, crossSystem }:
self = self.apps.${localSystem}; import ./apps {
nixpkgs = legacyPackages; self = self.apps.${system};
nixpkgsLocal = nixpkgsUpstream.legacyPackages.${localSystem}; nixpkgs = self.legacyPackages.${system};
inherit packages; nixpkgsLocal = nixpkgsFor.${localSystem};
}; packages = self.packages.${system};
});
checks = import ./tests { checks = forAllCrossSystems ({ system, localSystem, crossSystem }:
import ./tests {
inherit system localSystem crossSystem; inherit system localSystem crossSystem;
inherit self nixpkgs genode-depot; inherit self nixpkgs genode-depot;
inherit apps lib; apps = self.apps.${system};
genodepkgs = thisSystem self.packages; lib = self.lib.${system};
genodepkgs = self.packages.${system};
});
}; };
};
localSystems = [ "x86_64-linux" ];
crossSystems = [ "x86_64-genode" ];
forAllCrossSystems = f:
with builtins;
let
f' = localSystem: crossSystem:
let system = localSystem + "-" + crossSystem;
in {
name = system;
value = f { inherit system localSystem crossSystem; };
};
list = nixpkgs.lib.lists.crossLists f' [ localSystems crossSystems ];
attrSet = listToAttrs list;
in attrSet;
finalize = outputs:
with builtins;
let
outputs' = outputs // {
x86_64-linux = getAttr "x86_64-linux-x86_64-genode" outputs;
};
systems = attrNames outputs';
outputAttrs = attrNames (head (attrValues outputs'));
list = map (attr: {
name = attr;
value = listToAttrs (map (system: {
name = system;
value = getAttr attr (getAttr system outputs');
}) systems);
}) outputAttrs;
in listToAttrs list;
final = finalize (forAllCrossSystems mkOutput);
in final;
} }

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;