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