1# This module defines the packages that appear in
2# /run/current-system/sw.
3{
4 config,
5 lib,
6 pkgs,
7 ...
8}:
9let
10
11 corePackageNames = [
12 "acl"
13 "attr"
14 "bashInteractive" # bash with ncurses support
15 "bzip2"
16 "coreutils-full"
17 "cpio"
18 "curl"
19 "diffutils"
20 "findutils"
21 "gawk"
22 "getent"
23 "getconf"
24 "gnugrep"
25 "gnupatch"
26 "gnused"
27 "gnutar"
28 "gzip"
29 "xz"
30 "less"
31 "libcap"
32 "ncurses"
33 "netcat"
34 "mkpasswd"
35 "procps"
36 "su"
37 "time"
38 "util-linux"
39 "which"
40 "zstd"
41 ];
42 corePackages =
43 (map (
44 n:
45 let
46 pkg = pkgs.${n};
47 in
48 lib.setPrio ((pkg.meta.priority or lib.meta.defaultPriority) + 3) pkg
49 ) corePackageNames)
50 ++ [ pkgs.stdenv.cc.libc ];
51 corePackagesText = "[ ${lib.concatMapStringsSep " " (n: "pkgs.${n}") corePackageNames} ]";
52
53 defaultPackageNames = [
54 "perl"
55 "rsync"
56 "strace"
57 ];
58 defaultPackages = map (
59 n:
60 let
61 pkg = pkgs.${n};
62 in
63 lib.setPrio ((pkg.meta.priority or lib.meta.defaultPriority) + 3) pkg
64 ) defaultPackageNames;
65 defaultPackagesText = "[ ${lib.concatMapStringsSep " " (n: "pkgs.${n}") defaultPackageNames} ]";
66
67in
68
69{
70 options = {
71
72 environment = {
73
74 systemPackages = lib.mkOption {
75 type = lib.types.listOf lib.types.package;
76 default = [ ];
77 example = lib.literalExpression "[ pkgs.firefox pkgs.thunderbird ]";
78 description = ''
79 The set of packages that appear in
80 /run/current-system/sw. These packages are
81 automatically available to all users, and are
82 automatically updated every time you rebuild the system
83 configuration. (The latter is the main difference with
84 installing them in the default profile,
85 {file}`/nix/var/nix/profiles/default`.
86 '';
87 };
88
89 corePackages = lib.mkOption {
90 type = lib.types.listOf lib.types.package;
91 defaultText = lib.literalMD ''
92 these packages, with their `meta.priority` numerically increased
93 (thus lowering their installation priority):
94
95 ${corePackagesText}
96 '';
97 example = [ ];
98 description = ''
99 Set of core packages for a normal interactive system.
100
101 Only change this if you know what you're doing!
102
103 Like with systemPackages, packages are installed to
104 {file}`/run/current-system/sw`. They are
105 automatically available to all users, and are
106 automatically updated every time you rebuild the system
107 configuration.
108 '';
109 };
110
111 defaultPackages = lib.mkOption {
112 type = lib.types.listOf lib.types.package;
113 default = defaultPackages;
114 defaultText = lib.literalMD ''
115 these packages, with their `meta.priority` numerically increased
116 (thus lowering their installation priority):
117
118 ${defaultPackagesText}
119 '';
120 example = [ ];
121 description = ''
122 Set of default packages that aren't strictly necessary
123 for a running system, entries can be removed for a more
124 minimal NixOS installation.
125
126 Like with systemPackages, packages are installed to
127 {file}`/run/current-system/sw`. They are
128 automatically available to all users, and are
129 automatically updated every time you rebuild the system
130 configuration.
131 '';
132 };
133
134 pathsToLink = lib.mkOption {
135 type = lib.types.listOf lib.types.str;
136 # Note: We need `/lib' to be among `pathsToLink' for NSS modules
137 # to work.
138 default = [ ];
139 example = [ "/" ];
140 description = "List of directories to be symlinked in {file}`/run/current-system/sw`.";
141 };
142
143 extraOutputsToInstall = lib.mkOption {
144 type = lib.types.listOf lib.types.str;
145 default = [ ];
146 example = [
147 "dev"
148 "info"
149 ];
150 description = ''
151 Entries listed here will be appended to the `meta.outputsToInstall` attribute for each package in `environment.systemPackages`, and the files from the corresponding derivation outputs symlinked into {file}`/run/current-system/sw`.
152
153 For example, this can be used to install the `dev` and `info` outputs for all packages in the system environment, if they are available.
154
155 To use specific outputs instead of configuring them globally, select the corresponding attribute on the package derivation, e.g. `libxml2.dev` or `coreutils.info`.
156 '';
157 };
158
159 extraSetup = lib.mkOption {
160 type = lib.types.lines;
161 default = "";
162 description = "Shell fragments to be run after the system environment has been created. This should only be used for things that need to modify the internals of the environment, e.g. generating MIME caches. The environment being built can be accessed at $out.";
163 };
164
165 };
166
167 system = {
168
169 path = lib.mkOption {
170 internal = true;
171 description = ''
172 The packages you want in the boot environment.
173 '';
174 };
175
176 };
177
178 };
179
180 config = {
181
182 # Set this here so that it has the right priority and allows ergonomic
183 # merging.
184 environment.corePackages = corePackages;
185
186 environment.systemPackages = config.environment.corePackages ++ config.environment.defaultPackages;
187
188 environment.pathsToLink = [
189 "/bin"
190 "/etc/xdg"
191 "/etc/gtk-2.0"
192 "/etc/gtk-3.0"
193 "/lib" # FIXME: remove and update debug-info.nix
194 "/sbin"
195 "/share/emacs"
196 "/share/hunspell"
197 "/share/org"
198 "/share/themes"
199 "/share/vulkan"
200 "/share/kservices5"
201 "/share/kservicetypes5"
202 "/share/kxmlgui5"
203 "/share/systemd"
204 "/share/thumbnailers"
205 ];
206
207 system.path = pkgs.buildEnv {
208 name = "system-path";
209 paths = config.environment.systemPackages;
210 inherit (config.environment) pathsToLink extraOutputsToInstall;
211 ignoreCollisions = true;
212 # !!! Hacky, should modularise.
213 # outputs TODO: note that the tools will often not be linked by default
214 postBuild = ''
215 # Remove wrapped binaries, they shouldn't be accessible via PATH.
216 find $out/bin -maxdepth 1 -name ".*-wrapped" -type l -delete
217
218 if [ -x $out/bin/glib-compile-schemas -a -w $out/share/glib-2.0/schemas ]; then
219 $out/bin/glib-compile-schemas $out/share/glib-2.0/schemas
220 fi
221
222 ${config.environment.extraSetup}
223 '';
224 };
225
226 };
227}