6 , src ? fetchFromGitHub { owner = "NixOS"; repo = "nix"; rev = version; inherit hash; }
8 , maintainers ? with lib.maintainers; [ eelco lovesegfault artturin ]
11 assert (hash == null) -> (src != null);
13 atLeast24 = lib.versionAtLeast version "2.4pre";
14 atLeast25 = lib.versionAtLeast version "2.5pre";
15 atLeast27 = lib.versionAtLeast version "2.7pre";
16 atLeast210 = lib.versionAtLeast version "2.10pre";
17 atLeast213 = lib.versionAtLeast version "2.13pre";
18 atLeast214 = lib.versionAtLeast version "2.14pre";
19 atLeast218 = lib.versionAtLeast version "2.18pre";
20 atLeast219 = lib.versionAtLeast version "2.19pre";
21 atLeast220 = lib.versionAtLeast version "2.20pre";
22 atLeast221 = lib.versionAtLeast version "2.21pre";
23 atLeast224 = lib.versionAtLeast version "2.24pre";
24 atLeast225 = lib.versionAtLeast version "2.25pre";
25 # Major.minor versions unaffected by CVE-2024-27297
26 unaffectedByFodSandboxEscape = [
42 , busybox-sandbox-shell
48 , darwinMinVersionHook
82 , enableDocumentation ? stdenv.buildPlatform.canExecute stdenv.hostPlatform
83 , enableStatic ? stdenv.hostPlatform.isStatic
84 , withAWS ? !enableStatic && (stdenv.hostPlatform.isLinux || stdenv.hostPlatform.isDarwin), aws-sdk-cpp
85 , withLibseccomp ? lib.meta.availableOn stdenv.hostPlatform libseccomp, libseccomp
97 self = stdenv.mkDerivation {
100 version = "${version}${suffix}";
101 VERSION_SUFFIX = suffix;
107 ++ lib.optionals enableDocumentation [ "man" "doc" ];
109 hardeningEnable = lib.optionals (!stdenv.hostPlatform.isDarwin) [ "pie" ];
113 ] ++ lib.optional stdenv.hostPlatform.isMusl "fortify";
115 nativeInstallCheckInputs = lib.optional atLeast221 git ++ lib.optional atLeast219 man;
117 nativeBuildInputs = [
124 ] ++ lib.optionals (enableDocumentation && !atLeast24) [
129 ] ++ lib.optionals (enableDocumentation && atLeast24) [
130 (lib.getBin lowdown-unsandboxed)
132 ] ++ lib.optionals (atLeast213 && enableDocumentation) [
134 ] ++ lib.optionals stdenv.hostPlatform.isLinux [
151 ] ++ lib.optionals atLeast220 [
153 ] ++ lib.optionals (atLeast224 || lib.versionAtLeast version "pre20240626") [
155 ] ++ lib.optionals (atLeast225 && enableDocumentation) [
157 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
159 ] ++ lib.optionals (stdenv.hostPlatform.isx86_64) [
161 ] ++ lib.optionals atLeast214 [
163 ] ++ lib.optionals withLibseccomp [
165 ] ++ lib.optionals withAWS [
167 ] ++ lib.optional (atLeast218 && stdenv.hostPlatform.isDarwin) [
168 darwin.apple_sdk.libs.sandbox
169 ] ++ lib.optional (atLeast224 && stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) [
170 # Fix the following error with the default x86_64-darwin SDK:
172 # error: aligned allocation function of type 'void *(std::size_t, std::align_val_t)' is only available on macOS 10.13 or newer
174 # Despite the use of the 10.13 deployment target here, the aligned
175 # allocation function Clang uses with this setting actually works
176 # all the way back to 10.6.
177 (darwinMinVersionHook "10.13")
180 propagatedBuildInputs = [
182 ] ++ lib.optionals atLeast27 [
187 patchShebangs --build tests
191 # Copy libboost_context so we don't get all of Boost in our closure.
192 # https://github.com/NixOS/nixpkgs/issues/45462
193 lib.optionalString (!enableStatic) ''
195 cp -pd ${boost}/lib/{libboost_context*,libboost_thread*,libboost_system*} $out/lib
197 ${lib.optionalString stdenv.hostPlatform.isLinux ''
198 chmod u+w $out/lib/*.so.*
199 patchelf --set-rpath $out/lib:${lib.getLib stdenv.cc.cc}/lib $out/lib/libboost_thread.so.*
202 # On all versions before c9f51e87057652db0013289a95deffba495b35e7, which
203 # removes config.nix entirely and is not present in 2.3.x, we need to
204 # patch around an issue where the Nix configure step pulls in the build
205 # system's bash and other utilities when cross-compiling.
206 lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform && !atLeast24) ''
208 substitute corepkgs/config.nix.in tmp/config.nix.in \
209 --subst-var-by bash ${bash}/bin/bash \
210 --subst-var-by coreutils ${coreutils}/bin \
211 --subst-var-by bzip2 ${bzip2}/bin/bzip2 \
212 --subst-var-by gzip ${gzip}/bin/gzip \
213 --subst-var-by xz ${xz}/bin/xz \
214 --subst-var-by tar ${gnutar}/bin/tar \
215 --subst-var-by tr ${coreutils}/bin/tr
216 mv tmp/config.nix.in corepkgs/config.nix.in
220 "--with-store-dir=${storeDir}"
221 "--localstatedir=${stateDir}"
222 "--sysconfdir=${confDir}"
224 ] ++ lib.optionals (!enableDocumentation) [
226 ] ++ lib.optionals stdenv.hostPlatform.isLinux [
227 "--with-sandbox-shell=${busybox-sandbox-shell}/bin/busybox"
228 ] ++ lib.optionals (atLeast210 && stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isStatic) [
229 "--enable-embedded-sandbox-shell"
230 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform ? nix && stdenv.hostPlatform.nix ? system) [
231 "--with-system=${stdenv.hostPlatform.nix.system}"
232 ] ++ lib.optionals (!withLibseccomp) [
233 # RISC-V support in progress https://github.com/seccomp/libseccomp/pull/50
234 "--disable-seccomp-sandboxing"
235 ] ++ lib.optionals (atLeast210 && stdenv.cc.isGNU && !enableStatic) [
240 # gcc runs multi-threaded LTO using make and does not yet detect the new fifo:/path style
241 # of make jobserver. until gcc adds support for this we have to instruct make to use this
242 # old style or LTO builds will run their linking on only one thread, which takes forever.
243 "--jobserver-style=pipe"
244 "profiledir=$(out)/etc/profile.d"
245 ] ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) "PRECOMPILE_HEADERS=0"
246 ++ lib.optional (stdenv.hostPlatform.isDarwin) "PRECOMPILE_HEADERS=1";
248 installFlags = [ "sysconfdir=$(out)/etc" ];
250 doInstallCheck = true;
251 installCheckTarget = if atLeast210 then "installcheck" else null;
253 # socket path becomes too long otherwise
254 preInstallCheck = lib.optionalString stdenv.hostPlatform.isDarwin ''
255 export TMPDIR=$NIX_BUILD_TOP
257 # Prevent crashes in libcurl due to invoking Objective-C `+initialize` methods after `fork`.
258 # See http://sealiesoftware.com/blog/archive/2017/6/5/Objective-C_and_fork_in_macOS_1013.html.
259 + lib.optionalString stdenv.hostPlatform.isDarwin ''
260 export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
262 # See https://github.com/NixOS/nix/issues/5687
263 + lib.optionalString (atLeast25 && stdenv.hostPlatform.isDarwin) ''
264 echo "exit 99" > tests/gc-non-blocking.sh
265 '' # TODO: investigate why this broken
266 + lib.optionalString (atLeast25 && stdenv.hostPlatform.system == "aarch64-linux") ''
267 echo "exit 0" > tests/functional/flakes/show.sh
269 # nixStatic otherwise does not find its man pages in tests.
270 export MANPATH=$man/share/man:$MANPATH
273 separateDebugInfo = stdenv.hostPlatform.isLinux && (atLeast24 -> !enableStatic);
275 enableParallelBuilding = true;
278 inherit aws-sdk-cpp boehmgc;
280 perl-bindings = perl.pkgs.toPerlModule (callPackage ./nix-perl.nix { nix = self; inherit Security; });
283 srcVersion = runCommand "nix-src-version" {
286 # This file is an implementation detail, but it's a good sanity check
287 # If upstream changes that, we'll have to adapt.
288 srcVersion=$(cat ${src}/.version)
289 echo "Version in nix nix expression: $version"
290 echo "Version in nix.src: $srcVersion"
291 if [ "$version" != "$srcVersion" ]; then
292 echo "Version mismatch!"
298 /** Intended to test `lib`, but also a good smoke test for Nix */
299 nixpkgs-lib = import ../../../../lib/tests/test-with-nix.nix {
303 } // lib.optionalAttrs stdenv.hostPlatform.isLinux {
304 nixStatic = pkgsStatic.nixVersions.${self_attribute_name};
306 # Basic smoke tests that needs to pass when upgrading nix.
307 # Note that this test does only test the nixVersions.stable attribute.
308 misc = nixosTests.nix-misc.default;
309 upgrade = nixosTests.nix-upgrade;
310 simpleUefiSystemdBoot = nixosTests.installer.simpleUefiSystemdBoot;
311 } // lib.optionalAttrs (stdenv.hostPlatform.system == "x86_64-linux") {
312 nixi686 = pkgsi686Linux.nixVersions.${self_attribute_name};
316 # point 'nix edit' and ofborg at the file that defines the attribute,
317 # not this common file.
318 pos = builtins.unsafeGetAttrPos "version" args;
320 description = "Powerful package manager that makes package management reliable and reproducible";
322 Nix is a powerful package manager for Linux and other Unix systems that
323 makes package management reliable and reproducible. It provides atomic
324 upgrades and rollbacks, side-by-side installation of multiple versions of
325 a package, multi-user package management and easy setup of build
328 homepage = "https://nixos.org/";
329 license = licenses.lgpl21Plus;
331 platforms = platforms.unix;
332 # Requires refactorings in nixpkgs: https://github.com/NixOS/nixpkgs/pull/356983
333 broken = stdenv.hostPlatform.isDarwin && enableStatic;
334 outputsToInstall = [ "out" ] ++ optional enableDocumentation "man";
336 knownVulnerabilities = lib.optional (!builtins.elem (lib.versions.majorMinor version) unaffectedByFodSandboxEscape && !atLeast221) "CVE-2024-27297";