Skip to content

Commit ad31783

Browse files
committed
Extract the top-level logic out of all-packages.nix into pkgs/top-level/default.nix
1 parent a543a57 commit ad31783

3 files changed

Lines changed: 158 additions & 146 deletions

File tree

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ if ! builtins ? nixVersion || builtins.compareVersions requiredVersion builtins.
66

77
else
88

9-
import ./pkgs/top-level/all-packages.nix
9+
import ./pkgs/top-level

pkgs/top-level/all-packages.nix

Lines changed: 10 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,16 @@
1-
/* This file composes the Nix Packages collection. That is, it
2-
imports the functions that build the various packages, and calls
3-
them with appropriate arguments. The result is a set of all the
4-
packages in the Nix Packages collection for some particular
5-
platform. */
1+
{ system, bootStdenv, noSysDirs, gccWithCC, gccWithProfiling
2+
, config, crossSystem, platform, lib
3+
, pkgsWithOverrides, stdenvAdapters, helperFunctions
4+
, ... }:
5+
self: pkgs:
66

7-
8-
{ # The system (e.g., `i686-linux') for which to build the packages.
9-
system ? builtins.currentSystem
10-
11-
, # The standard environment to use. Only used for bootstrapping. If
12-
# null, the default standard environment is used.
13-
bootStdenv ? null
14-
15-
, # Non-GNU/Linux OSes are currently "impure" platforms, with their libc
16-
# outside of the store. Thus, GCC, GFortran, & co. must always look for
17-
# files in standard system directories (/usr/include, etc.)
18-
noSysDirs ? (system != "x86_64-freebsd" && system != "i686-freebsd"
19-
&& system != "x86_64-solaris"
20-
&& system != "x86_64-kfreebsd-gnu")
21-
22-
# More flags for the bootstrapping of stdenv.
23-
, gccWithCC ? true
24-
, gccWithProfiling ? true
25-
26-
, # Allow a configuration attribute set to be passed in as an
27-
# argument. Otherwise, it's read from $NIXPKGS_CONFIG or
28-
# ~/.nixpkgs/config.nix.
29-
config ? null
30-
31-
, crossSystem ? null
32-
, platform ? null
33-
}:
34-
35-
36-
let config_ = config; platform_ = platform; in # rename the function arguments
7+
with pkgs;
378

389
let
10+
defaultScope = pkgs // pkgs.xorg;
11+
in
3912

40-
lib = import ../../lib;
41-
42-
# The contents of the configuration file found at $NIXPKGS_CONFIG or
43-
# $HOME/.nixpkgs/config.nix.
44-
# for NIXOS (nixos-rebuild): use nixpkgs.config option
45-
config =
46-
let
47-
toPath = builtins.toPath;
48-
getEnv = x: if builtins ? getEnv then builtins.getEnv x else "";
49-
pathExists = name:
50-
builtins ? pathExists && builtins.pathExists (toPath name);
51-
52-
configFile = getEnv "NIXPKGS_CONFIG";
53-
homeDir = getEnv "HOME";
54-
configFile2 = homeDir + "/.nixpkgs/config.nix";
55-
56-
configExpr =
57-
if config_ != null then config_
58-
else if configFile != "" && pathExists configFile then import (toPath configFile)
59-
else if homeDir != "" && pathExists configFile2 then import (toPath configFile2)
60-
else {};
61-
62-
in
63-
# allow both:
64-
# { /* the config */ } and
65-
# { pkgs, ... } : { /* the config */ }
66-
if builtins.isFunction configExpr
67-
then configExpr { inherit pkgs; }
68-
else configExpr;
69-
70-
# Allow setting the platform in the config file. Otherwise, let's use a reasonable default (pc)
71-
72-
platformAuto = let
73-
platforms = (import ./platforms.nix);
74-
in
75-
if system == "armv6l-linux" then platforms.raspberrypi
76-
else if system == "armv7l-linux" then platforms.armv7l-hf-multiplatform
77-
else if system == "armv5tel-linux" then platforms.sheevaplug
78-
else if system == "mips64el-linux" then platforms.fuloong2f_n32
79-
else if system == "x86_64-linux" then platforms.pc64
80-
else if system == "i686-linux" then platforms.pc32
81-
else platforms.pcBase;
82-
83-
platform = if platform_ != null then platform_
84-
else config.platform or platformAuto;
85-
86-
topLevelArguments = {
87-
inherit system bootStdenv noSysDirs gccWithCC gccWithProfiling config
88-
crossSystem platform lib;
89-
};
90-
91-
# Allow packages to be overriden globally via the `packageOverrides'
92-
# configuration option, which must be a function that takes `pkgs'
93-
# as an argument and returns a set of new or overriden packages.
94-
# The `packageOverrides' function is called with the *original*
95-
# (un-overriden) set of packages, allowing packageOverrides
96-
# attributes to refer to the original attributes (e.g. "foo =
97-
# ... pkgs.foo ...").
98-
pkgs = pkgsWithOverrides (self: config.packageOverrides or (super: {}));
99-
100-
# stdenvOverrides is used to avoid circular dependencies for building the
101-
# standard build environment. This mechanism use the override mechanism to
102-
# implement some staged compilation of the stdenv.
103-
#
104-
# We don't want stdenv overrides in the case of cross-building, or
105-
# otherwise the basic overrided packages will not be built with the
106-
# crossStdenv adapter.
107-
stdenvOverrides = pkgs:
108-
lib.optionalAttrs (crossSystem == null && pkgs.stdenv ? overrides)
109-
(pkgs.stdenv.overrides pkgs);
110-
111-
# Return the complete set of packages, after applying the overrides
112-
# returned by the `overrider' function (see above). Warning: this
113-
# function is very expensive!
114-
pkgsWithOverrides = overrider:
115-
let
116-
# The un-overriden packages, passed to `overrider'.
117-
pkgs_6 = pkgsFun pkgs;
118-
119-
pkgs_7 = pkgs_6 // overrider pkgs pkgs_6;
120-
121-
# The overriden, final packages.
122-
pkgs = pkgs_7 // stdenvOverrides pkgs_6;
123-
in pkgs;
124-
125-
# The package compositions. Yes, this isn't properly indented.
126-
pkgsFun = pkgs:
127-
let
128-
defaultScope = pkgs // pkgs.xorg;
129-
130-
# Helper functions that are exported through `pkgs'.
131-
helperFunctions =
132-
stdenvAdapters //
133-
(import ../build-support/trivial-builders.nix { inherit lib; inherit (pkgs) stdenv; inherit (pkgs.xorg) lndir; });
134-
135-
stdenvAdapters =
136-
import ../stdenv/adapters.nix pkgs;
137-
138-
stdenvDefault = (import ./stdenv.nix topLevelArguments) {} pkgs;
139-
140-
self = with pkgs; {
13+
{
14114

14215
# Make some arguments passed to all-packages.nix available
14316
inherit system platform;
@@ -16443,13 +16316,5 @@ let
1644316316

1644416317
mg = callPackage ../applications/editors/mg { };
1644516318

16446-
}; # self =
16447-
16319+
}
1644816320

16449-
aliases = import ./aliases.nix self;
16450-
16451-
in
16452-
helperFunctions // stdenvDefault // self // aliases;
16453-
16454-
in
16455-
pkgs

pkgs/top-level/default.nix

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/* This file composes the Nix Packages collection. That is, it
2+
imports the functions that build the various packages, and calls
3+
them with appropriate arguments. The result is a set of all the
4+
packages in the Nix Packages collection for some particular
5+
platform. */
6+
7+
8+
{ # The system (e.g., `i686-linux') for which to build the packages.
9+
system ? builtins.currentSystem
10+
11+
, # The standard environment to use. Only used for bootstrapping. If
12+
# null, the default standard environment is used.
13+
bootStdenv ? null
14+
15+
, # Non-GNU/Linux OSes are currently "impure" platforms, with their libc
16+
# outside of the store. Thus, GCC, GFortran, & co. must always look for
17+
# files in standard system directories (/usr/include, etc.)
18+
noSysDirs ? (system != "x86_64-freebsd" && system != "i686-freebsd"
19+
&& system != "x86_64-solaris"
20+
&& system != "x86_64-kfreebsd-gnu")
21+
22+
# More flags for the bootstrapping of stdenv.
23+
, gccWithCC ? true
24+
, gccWithProfiling ? true
25+
26+
, # Allow a configuration attribute set to be passed in as an
27+
# argument. Otherwise, it's read from $NIXPKGS_CONFIG or
28+
# ~/.nixpkgs/config.nix.
29+
config ? null
30+
31+
, crossSystem ? null
32+
, platform ? null
33+
}:
34+
35+
36+
let config_ = config; platform_ = platform; in # rename the function arguments
37+
38+
let
39+
40+
lib = import ../../lib;
41+
42+
# The contents of the configuration file found at $NIXPKGS_CONFIG or
43+
# $HOME/.nixpkgs/config.nix.
44+
# for NIXOS (nixos-rebuild): use nixpkgs.config option
45+
config =
46+
let
47+
toPath = builtins.toPath;
48+
getEnv = x: if builtins ? getEnv then builtins.getEnv x else "";
49+
pathExists = name:
50+
builtins ? pathExists && builtins.pathExists (toPath name);
51+
52+
configFile = getEnv "NIXPKGS_CONFIG";
53+
homeDir = getEnv "HOME";
54+
configFile2 = homeDir + "/.nixpkgs/config.nix";
55+
56+
configExpr =
57+
if config_ != null then config_
58+
else if configFile != "" && pathExists configFile then import (toPath configFile)
59+
else if homeDir != "" && pathExists configFile2 then import (toPath configFile2)
60+
else {};
61+
62+
in
63+
# allow both:
64+
# { /* the config */ } and
65+
# { pkgs, ... } : { /* the config */ }
66+
if builtins.isFunction configExpr
67+
then configExpr { inherit pkgs; }
68+
else configExpr;
69+
70+
# Allow setting the platform in the config file. Otherwise, let's use a reasonable default (pc)
71+
72+
platformAuto = let
73+
platforms = (import ./platforms.nix);
74+
in
75+
if system == "armv6l-linux" then platforms.raspberrypi
76+
else if system == "armv7l-linux" then platforms.armv7l-hf-multiplatform
77+
else if system == "armv5tel-linux" then platforms.sheevaplug
78+
else if system == "mips64el-linux" then platforms.fuloong2f_n32
79+
else if system == "x86_64-linux" then platforms.pc64
80+
else if system == "i686-linux" then platforms.pc32
81+
else platforms.pcBase;
82+
83+
platform = if platform_ != null then platform_
84+
else config.platform or platformAuto;
85+
86+
topLevelArguments = {
87+
inherit system bootStdenv noSysDirs gccWithCC gccWithProfiling config
88+
crossSystem platform lib;
89+
};
90+
91+
# Allow packages to be overriden globally via the `packageOverrides'
92+
# configuration option, which must be a function that takes `pkgs'
93+
# as an argument and returns a set of new or overriden packages.
94+
# The `packageOverrides' function is called with the *original*
95+
# (un-overriden) set of packages, allowing packageOverrides
96+
# attributes to refer to the original attributes (e.g. "foo =
97+
# ... pkgs.foo ...").
98+
pkgs = pkgsWithOverrides (self: config.packageOverrides or (super: {}));
99+
100+
# stdenvOverrides is used to avoid circular dependencies for building the
101+
# standard build environment. This mechanism use the override mechanism to
102+
# implement some staged compilation of the stdenv.
103+
#
104+
# We don't want stdenv overrides in the case of cross-building, or
105+
# otherwise the basic overrided packages will not be built with the
106+
# crossStdenv adapter.
107+
stdenvOverrides = pkgs:
108+
lib.optionalAttrs (crossSystem == null && pkgs.stdenv ? overrides)
109+
(pkgs.stdenv.overrides pkgs);
110+
111+
# Return the complete set of packages, after applying the overrides
112+
# returned by the `overrider' function (see above). Warning: this
113+
# function is very expensive!
114+
pkgsWithOverrides = overrider:
115+
let
116+
# The un-overriden packages, passed to `overrider'.
117+
pkgs_6 = pkgsFun pkgs;
118+
119+
pkgs_7 = pkgs_6 // overrider pkgs pkgs_6;
120+
121+
# The overriden, final packages.
122+
pkgs = pkgs_7 // stdenvOverrides pkgs_6;
123+
in pkgs;
124+
125+
# The package compositions. Yes, this isn't properly indented.
126+
pkgsFun = pkgs:
127+
let
128+
# Helper functions that are exported through `pkgs'.
129+
helperFunctions =
130+
stdenvAdapters //
131+
(import ../build-support/trivial-builders.nix { inherit lib; inherit (pkgs) stdenv; inherit (pkgs.xorg) lndir; });
132+
133+
stdenvAdapters =
134+
import ../stdenv/adapters.nix pkgs;
135+
136+
stdenvDefault = (import ./stdenv.nix topLevelArguments) {} pkgs;
137+
138+
selfArgs = topLevelArguments // { inherit pkgsWithOverrides stdenvAdapters helperFunctions; };
139+
self = (import ./all-packages.nix selfArgs) self pkgs;
140+
141+
aliases = import ./aliases.nix self;
142+
143+
in
144+
helperFunctions // stdenvDefault // self // aliases;
145+
146+
in
147+
pkgs

0 commit comments

Comments
 (0)