git.iko.soy/typeable/nixpkgs
on master help sign in
release-lib: Cache cross nixpkgs evals too

This will help with release-cross.nix eval time. It also allowed me to share code between the cross and native helpers.

commit79c713bc1498ccceed9f8d2fc0b8d29b1b45a209 authorJohn Ericson <John.Ericson@Obsidian.Systems> dateThu 6 Sep 2018, 14:28 (8 years ago) parentaa964c8
2 files changed+63−39
pkgs/top-level/release-cross.nix+3−3 pkgs/top-level/release-lib.nix+60−36
pkgs/top-level/release-cross.nix+3−3
@@ -81,11 +81,11 @@ in
8181 # good idea lest there be some irrelevant pass-through debug attrs that
8282 # cause false negatives.
8383 testEqualOne = path: system: let
84− f = path: attrs: builtins.toString (lib.getAttrFromPath path (allPackages attrs));
84+ f = path: crossSystem: system: builtins.toString (lib.getAttrFromPath path (pkgsForCross crossSystem system));
8585 in assertTrue (
86− f path { inherit system; }
86+ f path null system
8787 ==
88− f (["buildPackages"] ++ path) { inherit system crossSystem; }
88+ f (["buildPackages"] ++ path) crossSystem system
8989 );
9090
9191 testEqual = path: systems: forMatchingSystems systems (testEqualOne path);
pkgs/top-level/release-lib.nix+60−36
@@ -11,8 +11,6 @@ in with lib;
1111
1212rec {
1313
14− allPackages = args: packageSet (args // nixpkgsArgs);
15−
1614 pkgs = packageSet (lib.recursiveUpdate { system = "x86_64-linux"; config.allowUnsupportedSystem = true; } nixpkgsArgs);
1715 inherit lib;
1816
@@ -23,29 +21,53 @@ rec {
2321 /* !!! Hack: poor man's memoisation function. Necessary to prevent
2422 Nixpkgs from being evaluated again and again for every
2523 job/platform pair. */
26− pkgsFor = system:
27− if system == "x86_64-linux" then pkgs_x86_64_linux
28− else if system == "i686-linux" then pkgs_i686_linux
29− else if system == "aarch64-linux" then pkgs_aarch64_linux
30− else if system == "armv6l-linux" then pkgs_armv6l_linux
31− else if system == "armv7l-linux" then pkgs_armv7l_linux
32− else if system == "x86_64-darwin" then pkgs_x86_64_darwin
33− else if system == "x86_64-freebsd" then pkgs_x86_64_freebsd
34− else if system == "i686-freebsd" then pkgs_i686_freebsd
35− else if system == "i686-cygwin" then pkgs_i686_cygwin
36− else if system == "x86_64-cygwin" then pkgs_x86_64_cygwin
37− else abort "unsupported system type: ${system}";
38−
39− pkgs_x86_64_linux = allPackages { system = "x86_64-linux"; };
40− pkgs_i686_linux = allPackages { system = "i686-linux"; };
41− pkgs_aarch64_linux = allPackages { system = "aarch64-linux"; };
42− pkgs_armv6l_linux = allPackages { system = "armv6l-linux"; };
43− pkgs_armv7l_linux = allPackages { system = "armv7l-linux"; };
44− pkgs_x86_64_darwin = allPackages { system = "x86_64-darwin"; };
45− pkgs_x86_64_freebsd = allPackages { system = "x86_64-freebsd"; };
46− pkgs_i686_freebsd = allPackages { system = "i686-freebsd"; };
47− pkgs_i686_cygwin = allPackages { system = "i686-cygwin"; };
48− pkgs_x86_64_cygwin = allPackages { system = "x86_64-cygwin"; };
24+ mkPkgsFor = crossSystem: let
25+ packageSet' = args: packageSet (args // { inherit crossSystem; } // nixpkgsArgs);
26+
27+ pkgs_x86_64_linux = packageSet' { system = "x86_64-linux"; };
28+ pkgs_i686_linux = packageSet' { system = "i686-linux"; };
29+ pkgs_aarch64_linux = packageSet' { system = "aarch64-linux"; };
30+ pkgs_armv6l_linux = packageSet' { system = "armv6l-linux"; };
31+ pkgs_armv7l_linux = packageSet' { system = "armv7l-linux"; };
32+ pkgs_x86_64_darwin = packageSet' { system = "x86_64-darwin"; };
33+ pkgs_x86_64_freebsd = packageSet' { system = "x86_64-freebsd"; };
34+ pkgs_i686_freebsd = packageSet' { system = "i686-freebsd"; };
35+ pkgs_i686_cygwin = packageSet' { system = "i686-cygwin"; };
36+ pkgs_x86_64_cygwin = packageSet' { system = "x86_64-cygwin"; };
37+
38+ in system:
39+ if system == "x86_64-linux" then pkgs_x86_64_linux
40+ else if system == "i686-linux" then pkgs_i686_linux
41+ else if system == "aarch64-linux" then pkgs_aarch64_linux
42+ else if system == "armv6l-linux" then pkgs_armv6l_linux
43+ else if system == "armv7l-linux" then pkgs_armv7l_linux
44+ else if system == "x86_64-darwin" then pkgs_x86_64_darwin
45+ else if system == "x86_64-freebsd" then pkgs_x86_64_freebsd
46+ else if system == "i686-freebsd" then pkgs_i686_freebsd
47+ else if system == "i686-cygwin" then pkgs_i686_cygwin
48+ else if system == "x86_64-cygwin" then pkgs_x86_64_cygwin
49+ else abort "unsupported system type: ${system}";
50+
51+ inherit (pkgsForCross null) pkgsFor;
52+
53+
54+ # More poor man's memoisation
55+ pkgsForCross = let
56+ examplesByConfig = lib.flip lib.mapAttrs'
57+ (builtins.removeAttrs lib.systems.examples [ "riscv" ])
58+ (_: crossSystem: nameValuePair crossSystem.config {
59+ inherit crossSystem;
60+ pkgsFor = mkPkgsFor crossSystem;
61+ });
62+ native = mkPkgsFor null;
63+ in crossSystem: let
64+ errorMsg = "unsupported crossSystem: ${toString crossSystem.config or "<something without config>"}";
65+ candidate = examplesByConfig.${crossSystem.config} or (throw errorMsg);
66+ in if crossSystem == null
67+ then native
68+ else if lib.matchAttrs crossSystem candidate.crossSystem
69+ then candidate.pkgsFor
70+ else throw errorMsg;
4971
5072
5173 # Given a list of 'meta.platforms'-style patterns, return the sublist of
@@ -90,30 +112,32 @@ rec {
90112 platform as an argument . We return an attribute set containing
91113 a derivation for each supported platform, i.e. ‘{ x86_64-linux =
92114 f pkgs_x86_64_linux; i686-linux = f pkgs_i686_linux; ... }’. */
93− testOn = metaPatterns: f: forMatchingSystems metaPatterns
94− (system: hydraJob' (f (pkgsFor system)));
115+ testOn = testOnCross null;
95116
96117
97118 /* Similar to the testOn function, but with an additional
98− 'crossSystem' parameter for allPackages, defining the target
119+ 'crossSystem' parameter for packageSet', defining the target
99120 platform for cross builds. */
100121 testOnCross = crossSystem: metaPatterns: f: forMatchingSystems metaPatterns
101− (system: hydraJob' (f (allPackages { inherit system crossSystem; })));
122+ (system: hydraJob' (f (pkgsForCross crossSystem system)));
102123
103124
104125 /* Given a nested set where the leaf nodes are lists of platforms,
105126 map each leaf node to `testOn [platforms...] (pkgs:
106127 pkgs.<attrPath>)'. */
107− mapTestOn = mapAttrsRecursive
108− (path: metaPatterns: testOn metaPatterns (pkgs: getAttrFromPath path pkgs));
128+ mapTestOn = _mapTestOnHelper id null;
109129
110130
111− /* Similar to the testOn function, but with an additional 'crossSystem'
112− * parameter for allPackages, defining the target platform for cross builds,
113− * and triggering the build of the host derivation (cross built - crossDrv). */
114− mapTestOnCross = crossSystem: mapAttrsRecursive
131+ _mapTestOnHelper = f: crossSystem: mapAttrsRecursive
115132 (path: metaPatterns: testOnCross crossSystem metaPatterns
116− (pkgs: addMetaAttrs { maintainers = crossMaintainers; } (getAttrFromPath path pkgs)));
133+ (pkgs: f (getAttrFromPath path pkgs)));
134+
135+
136+ /* Similar to the testOn function, but with an additional 'crossSystem'
137+ * parameter for packageSet', defining the target platform for cross builds,
138+ * and triggering the build of the host derivation. */
139+ mapTestOnCross = _mapTestOnHelper
140+ (addMetaAttrs { maintainers = crossMaintainers; });
117141
118142
119143 /* Recursively map a (nested) set of derivations to an isomorphic