2023-11-20 00:23:34 +02:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
fetchFromGitHub,
|
2022-01-26 11:31:20 -08:00
|
|
|
version,
|
|
|
|
suffix ? "",
|
2023-05-31 11:35:00 -04:00
|
|
|
hash ? null,
|
|
|
|
src ? fetchFromGitHub {
|
|
|
|
owner = "NixOS";
|
|
|
|
repo = "nix";
|
2025-04-08 02:51:45 -04:00
|
|
|
rev = version;
|
2023-05-31 11:35:00 -04:00
|
|
|
inherit hash;
|
|
|
|
},
|
2022-01-26 11:31:20 -08:00
|
|
|
patches ? [ ],
|
2025-06-29 14:41:47 +02:00
|
|
|
knownVulnerabilities ? [ ],
|
2025-03-26 09:17:19 +01:00
|
|
|
maintainers ? [
|
|
|
|
lib.maintainers.lovesegfault
|
|
|
|
lib.maintainers.artturin
|
|
|
|
],
|
|
|
|
teams ? [ lib.teams.nix ],
|
2024-05-24 07:29:01 +01:00
|
|
|
self_attribute_name,
|
2023-12-26 10:47:29 +00:00
|
|
|
}@args:
|
2023-05-31 11:35:00 -04:00
|
|
|
assert (hash == null) -> (src != null);
|
2022-01-26 11:31:20 -08:00
|
|
|
let
|
2024-11-18 20:13:40 +01:00
|
|
|
atLeast225 = lib.versionAtLeast version "2.25pre";
|
2022-01-26 11:31:20 -08:00
|
|
|
in
|
2022-01-24 23:07:22 -08:00
|
|
|
{
|
|
|
|
stdenv,
|
|
|
|
autoconf-archive,
|
|
|
|
autoreconfHook,
|
|
|
|
bash,
|
|
|
|
bison,
|
|
|
|
boehmgc,
|
|
|
|
boost,
|
|
|
|
brotli,
|
|
|
|
busybox-sandbox-shell,
|
|
|
|
bzip2,
|
|
|
|
callPackage,
|
|
|
|
coreutils,
|
2022-08-31 17:54:32 +10:00
|
|
|
curl,
|
2023-11-06 21:30:01 +01:00
|
|
|
docbook_xsl_ns,
|
|
|
|
docbook5,
|
2022-01-24 23:07:22 -08:00
|
|
|
editline,
|
|
|
|
flex,
|
2024-03-11 22:23:44 +01:00
|
|
|
git,
|
2022-01-24 23:07:22 -08:00
|
|
|
gnutar,
|
|
|
|
gtest,
|
|
|
|
gzip,
|
|
|
|
jq,
|
|
|
|
lib,
|
|
|
|
libarchive,
|
|
|
|
libcpuid,
|
2024-01-31 13:42:10 +01:00
|
|
|
libgit2,
|
2022-01-24 23:07:22 -08:00
|
|
|
libsodium,
|
2023-11-06 21:30:01 +01:00
|
|
|
libxml2,
|
|
|
|
libxslt,
|
2022-01-24 23:07:22 -08:00
|
|
|
lowdown,
|
2024-10-06 21:02:23 +01:00
|
|
|
lowdown-unsandboxed,
|
2024-06-27 21:12:40 +03:00
|
|
|
toml11,
|
2024-03-11 22:23:44 +01:00
|
|
|
man,
|
2022-01-24 23:07:22 -08:00
|
|
|
mdbook,
|
2023-01-18 07:12:50 +10:00
|
|
|
mdbook-linkcheck,
|
2022-01-24 23:07:22 -08:00
|
|
|
nlohmann_json,
|
2024-05-30 14:32:30 +02:00
|
|
|
nixosTests,
|
2022-01-24 23:07:22 -08:00
|
|
|
openssl,
|
|
|
|
perl,
|
2024-11-18 20:13:40 +01:00
|
|
|
python3,
|
2022-01-24 23:07:22 -08:00
|
|
|
pkg-config,
|
2023-03-01 07:32:33 +10:00
|
|
|
rapidcheck,
|
2022-01-24 23:07:22 -08:00
|
|
|
sqlite,
|
|
|
|
util-linuxMinimal,
|
|
|
|
xz,
|
2024-08-17 23:06:55 +02:00
|
|
|
enableDocumentation ? stdenv.buildPlatform.canExecute stdenv.hostPlatform,
|
2022-01-24 23:07:22 -08:00
|
|
|
enableStatic ? stdenv.hostPlatform.isStatic,
|
2025-07-15 14:45:49 +02:00
|
|
|
withAWS ?
|
|
|
|
lib.meta.availableOn stdenv.hostPlatform aws-c-common
|
|
|
|
&& !enableStatic
|
|
|
|
&& (stdenv.hostPlatform.isLinux || stdenv.hostPlatform.isDarwin),
|
|
|
|
aws-c-common,
|
2022-01-24 23:07:22 -08:00
|
|
|
aws-sdk-cpp,
|
|
|
|
withLibseccomp ? lib.meta.availableOn stdenv.hostPlatform libseccomp,
|
|
|
|
libseccomp,
|
|
|
|
|
|
|
|
confDir,
|
|
|
|
stateDir,
|
|
|
|
storeDir,
|
2022-08-30 16:49:27 +02:00
|
|
|
|
|
|
|
# passthru tests
|
|
|
|
pkgsi686Linux,
|
2024-09-13 12:12:01 +02:00
|
|
|
pkgsStatic,
|
2024-06-28 14:41:48 +02:00
|
|
|
runCommand,
|
2024-08-17 12:30:27 +02:00
|
|
|
pkgs,
|
2022-03-20 13:03:39 -04:00
|
|
|
}:
|
|
|
|
let
|
|
|
|
self = stdenv.mkDerivation {
|
2022-01-24 23:07:22 -08:00
|
|
|
pname = "nix";
|
|
|
|
|
|
|
|
version = "${version}${suffix}";
|
2022-01-26 11:31:20 -08:00
|
|
|
VERSION_SUFFIX = suffix;
|
|
|
|
|
2022-01-24 23:07:22 -08:00
|
|
|
inherit src patches;
|
|
|
|
|
|
|
|
outputs = [
|
2025-04-01 20:10:43 +02:00
|
|
|
"out"
|
2022-01-24 23:07:22 -08:00
|
|
|
"dev"
|
|
|
|
]
|
|
|
|
++ lib.optionals enableDocumentation [
|
2025-04-01 20:10:43 +02:00
|
|
|
"man"
|
|
|
|
"doc"
|
2022-01-24 23:07:22 -08:00
|
|
|
];
|
|
|
|
|
2024-07-20 11:45:48 +01:00
|
|
|
hardeningEnable = lib.optionals (!stdenv.hostPlatform.isDarwin) [ "pie" ];
|
2023-09-05 18:53:03 +02:00
|
|
|
|
2024-12-10 06:33:10 +01:00
|
|
|
hardeningDisable = [
|
|
|
|
"shadowstack"
|
|
|
|
]
|
|
|
|
++ lib.optional stdenv.hostPlatform.isMusl "fortify";
|
2024-08-17 23:06:55 +02:00
|
|
|
|
2025-07-24 16:08:14 +02:00
|
|
|
nativeInstallCheckInputs = [
|
2025-04-01 20:10:43 +02:00
|
|
|
git
|
2024-12-10 06:33:10 +01:00
|
|
|
man
|
2022-01-24 23:07:22 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
pkg-config
|
|
|
|
autoconf-archive
|
2024-12-10 06:33:10 +01:00
|
|
|
autoreconfHook
|
2025-04-01 20:10:43 +02:00
|
|
|
bison
|
2024-12-10 06:33:10 +01:00
|
|
|
flex
|
2025-04-01 20:10:43 +02:00
|
|
|
jq
|
2024-12-10 06:33:10 +01:00
|
|
|
]
|
2025-07-24 16:08:14 +02:00
|
|
|
++ lib.optionals enableDocumentation [
|
|
|
|
(lib.getBin lowdown-unsandboxed)
|
|
|
|
mdbook
|
|
|
|
mdbook-linkcheck
|
|
|
|
]
|
2023-11-06 21:30:01 +01:00
|
|
|
++ lib.optionals stdenv.hostPlatform.isLinux [
|
2024-12-10 06:33:10 +01:00
|
|
|
util-linuxMinimal
|
2022-01-24 23:07:22 -08:00
|
|
|
];
|
|
|
|
|
2022-03-10 15:29:58 +01:00
|
|
|
buildInputs = [
|
|
|
|
boost
|
2025-04-01 20:10:43 +02:00
|
|
|
brotli
|
|
|
|
bzip2
|
|
|
|
curl
|
|
|
|
editline
|
2022-01-24 23:07:22 -08:00
|
|
|
libsodium
|
2025-04-01 20:10:43 +02:00
|
|
|
openssl
|
|
|
|
sqlite
|
|
|
|
xz
|
|
|
|
gtest
|
|
|
|
libarchive
|
|
|
|
lowdown
|
|
|
|
libgit2
|
|
|
|
toml11
|
2024-12-10 06:33:10 +01:00
|
|
|
rapidcheck
|
2025-04-01 20:10:43 +02:00
|
|
|
]
|
2024-12-10 06:33:10 +01:00
|
|
|
++ lib.optionals (atLeast225 && enableDocumentation) [
|
2025-04-01 20:10:43 +02:00
|
|
|
python3
|
|
|
|
]
|
2023-11-06 21:30:01 +01:00
|
|
|
++ lib.optionals (stdenv.hostPlatform.isx86_64) [
|
2025-04-01 20:10:43 +02:00
|
|
|
libcpuid
|
|
|
|
]
|
2022-01-24 23:07:22 -08:00
|
|
|
++ lib.optionals withLibseccomp [
|
|
|
|
libseccomp
|
2025-04-01 20:10:43 +02:00
|
|
|
]
|
2022-01-24 23:07:22 -08:00
|
|
|
++ lib.optionals withAWS [
|
2022-01-26 11:31:20 -08:00
|
|
|
aws-sdk-cpp
|
2022-03-10 15:29:58 +01:00
|
|
|
];
|
2022-01-24 23:07:22 -08:00
|
|
|
|
2023-07-20 10:57:09 +00:00
|
|
|
propagatedBuildInputs = [
|
2025-04-01 20:10:43 +02:00
|
|
|
boehmgc
|
2023-07-20 10:57:09 +00:00
|
|
|
nlohmann_json
|
|
|
|
];
|
|
|
|
|
2024-11-07 09:43:39 +00:00
|
|
|
postPatch = ''
|
2022-01-24 23:07:22 -08:00
|
|
|
patchShebangs --build tests
|
|
|
|
'';
|
|
|
|
|
|
|
|
preConfigure =
|
|
|
|
# Copy libboost_context so we don't get all of Boost in our closure.
|
|
|
|
# https://github.com/NixOS/nixpkgs/issues/45462
|
|
|
|
lib.optionalString (!enableStatic) ''
|
|
|
|
mkdir -p $out/lib
|
2022-01-26 12:57:25 -08:00
|
|
|
cp -pd ${boost}/lib/{libboost_context*,libboost_thread*,libboost_system*} $out/lib
|
2024-12-10 06:33:10 +01:00
|
|
|
rm -f $out/lib/*.a
|
|
|
|
${lib.optionalString stdenv.hostPlatform.isLinux ''
|
2022-01-24 23:07:22 -08:00
|
|
|
chmod u+w $out/lib/*.so.*
|
2024-12-10 06:33:10 +01:00
|
|
|
patchelf --set-rpath $out/lib:${lib.getLib stdenv.cc.cc}/lib $out/lib/libboost_thread.so.*
|
2025-04-01 20:10:43 +02:00
|
|
|
''}
|
2025-07-24 16:08:14 +02:00
|
|
|
'';
|
2022-01-24 23:07:22 -08:00
|
|
|
|
|
|
|
configureFlags = [
|
2023-02-09 14:51:24 +01:00
|
|
|
"--with-store-dir=${storeDir}"
|
2022-01-24 23:07:22 -08:00
|
|
|
"--localstatedir=${stateDir}"
|
2022-01-31 22:09:37 +00:00
|
|
|
"--sysconfdir=${confDir}"
|
2022-01-24 23:07:22 -08:00
|
|
|
"--enable-gc"
|
2022-01-31 22:09:37 +00:00
|
|
|
]
|
|
|
|
++ lib.optionals (!enableDocumentation) [
|
2022-01-24 23:07:22 -08:00
|
|
|
"--disable-doc-gen"
|
2025-04-01 20:10:43 +02:00
|
|
|
]
|
2024-12-10 06:33:10 +01:00
|
|
|
++ lib.optionals stdenv.hostPlatform.isLinux [
|
2022-01-31 22:09:37 +00:00
|
|
|
"--with-sandbox-shell=${busybox-sandbox-shell}/bin/busybox"
|
2025-04-01 20:10:43 +02:00
|
|
|
]
|
2025-07-24 16:08:14 +02:00
|
|
|
++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isStatic) [
|
2022-08-06 14:43:08 -07:00
|
|
|
"--enable-embedded-sandbox-shell"
|
2025-04-01 20:10:43 +02:00
|
|
|
]
|
|
|
|
++
|
2022-01-24 23:07:22 -08:00
|
|
|
lib.optionals
|
2025-04-01 20:10:43 +02:00
|
|
|
(
|
2022-01-31 22:09:37 +00:00
|
|
|
stdenv.hostPlatform != stdenv.buildPlatform
|
2024-12-10 06:33:10 +01:00
|
|
|
&& stdenv.hostPlatform ? nix
|
|
|
|
&& stdenv.hostPlatform.nix ? system
|
2025-04-01 20:10:43 +02:00
|
|
|
)
|
|
|
|
[
|
2022-01-31 22:09:37 +00:00
|
|
|
"--with-system=${stdenv.hostPlatform.nix.system}"
|
2025-04-01 20:10:43 +02:00
|
|
|
]
|
2022-01-24 23:07:22 -08:00
|
|
|
++ lib.optionals (!withLibseccomp) [
|
2022-01-31 22:09:37 +00:00
|
|
|
# RISC-V support in progress https://github.com/seccomp/libseccomp/pull/50
|
2022-01-24 23:07:22 -08:00
|
|
|
"--disable-seccomp-sandboxing"
|
2025-04-01 20:10:43 +02:00
|
|
|
]
|
2025-07-24 16:08:14 +02:00
|
|
|
++ lib.optionals (stdenv.cc.isGNU && !enableStatic) [
|
2022-07-14 23:23:43 +01:00
|
|
|
"--enable-lto"
|
2022-01-31 22:09:37 +00:00
|
|
|
];
|
2022-01-24 23:07:22 -08:00
|
|
|
|
2025-06-03 20:32:30 +00:00
|
|
|
env.CXXFLAGS = toString (
|
|
|
|
lib.optionals (lib.versionAtLeast lowdown.version "1.4.0") [
|
|
|
|
# Autotools based build system wasn't updated with the backport of
|
|
|
|
# https://github.com/NixOS/nix/pull/12115, so set the define explicitly.
|
|
|
|
"-DHAVE_LOWDOWN_1_4"
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2022-01-24 23:07:22 -08:00
|
|
|
makeFlags = [
|
2023-02-09 14:51:24 +01:00
|
|
|
# gcc runs multi-threaded LTO using make and does not yet detect the new fifo:/path style
|
2022-01-24 23:07:22 -08:00
|
|
|
# of make jobserver. until gcc adds support for this we have to instruct make to use this
|
|
|
|
# old style or LTO builds will run their linking on only one thread, which takes forever.
|
2023-02-09 14:51:24 +01:00
|
|
|
"--jobserver-style=pipe"
|
2022-01-24 23:07:22 -08:00
|
|
|
"profiledir=$(out)/etc/profile.d"
|
|
|
|
]
|
2024-12-10 06:33:10 +01:00
|
|
|
++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) "PRECOMPILE_HEADERS=0"
|
2022-01-24 23:07:22 -08:00
|
|
|
++ lib.optional (stdenv.hostPlatform.isDarwin) "PRECOMPILE_HEADERS=1";
|
|
|
|
|
2024-12-10 06:33:10 +01:00
|
|
|
installFlags = [ "sysconfdir=$(out)/etc" ];
|
2022-01-24 23:07:22 -08:00
|
|
|
|
|
|
|
doInstallCheck = true;
|
2025-07-24 16:08:14 +02:00
|
|
|
installCheckTarget = "installcheck";
|
2022-01-24 23:07:22 -08:00
|
|
|
|
2024-12-10 06:33:10 +01:00
|
|
|
# socket path becomes too long otherwise
|
|
|
|
preInstallCheck =
|
2024-01-04 18:57:10 -05:00
|
|
|
lib.optionalString stdenv.hostPlatform.isDarwin ''
|
2024-12-10 06:33:10 +01:00
|
|
|
export TMPDIR=$NIX_BUILD_TOP
|
2025-04-01 20:10:43 +02:00
|
|
|
''
|
2024-12-10 06:33:10 +01:00
|
|
|
# Prevent crashes in libcurl due to invoking Objective-C `+initialize` methods after `fork`.
|
2024-01-04 18:57:10 -05:00
|
|
|
# See http://sealiesoftware.com/blog/archive/2017/6/5/Objective-C_and_fork_in_macOS_1013.html.
|
|
|
|
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
|
2024-12-10 06:33:10 +01:00
|
|
|
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
|
2025-04-01 20:10:43 +02:00
|
|
|
''
|
2024-12-10 06:33:10 +01:00
|
|
|
# See https://github.com/NixOS/nix/issues/5687
|
2025-07-24 16:08:14 +02:00
|
|
|
+ lib.optionalString (stdenv.hostPlatform.isDarwin) ''
|
2024-12-10 06:33:10 +01:00
|
|
|
echo "exit 99" > tests/gc-non-blocking.sh
|
2024-09-10 16:00:25 +02:00
|
|
|
'' # TODO: investigate why this broken
|
2025-07-24 16:08:14 +02:00
|
|
|
+ lib.optionalString (stdenv.hostPlatform.system == "aarch64-linux") ''
|
2024-09-10 16:00:25 +02:00
|
|
|
echo "exit 0" > tests/functional/flakes/show.sh
|
2025-04-01 20:10:43 +02:00
|
|
|
''
|
|
|
|
+ ''
|
2024-12-10 06:33:10 +01:00
|
|
|
# nixStatic otherwise does not find its man pages in tests.
|
2024-08-17 23:06:55 +02:00
|
|
|
export MANPATH=$man/share/man:$MANPATH
|
2024-12-10 06:33:10 +01:00
|
|
|
'';
|
2022-01-24 23:07:22 -08:00
|
|
|
|
2025-07-24 16:08:14 +02:00
|
|
|
separateDebugInfo = stdenv.hostPlatform.isLinux && !enableStatic;
|
2022-01-24 23:07:22 -08:00
|
|
|
|
2022-08-30 16:49:27 +02:00
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit aws-sdk-cpp boehmgc;
|
|
|
|
|
|
|
|
perl-bindings = perl.pkgs.toPerlModule (
|
|
|
|
callPackage ./nix-perl.nix {
|
|
|
|
nix = self;
|
2025-04-01 20:10:43 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2025-01-22 15:35:54 +01:00
|
|
|
tests = import ./tests.nix {
|
|
|
|
inherit
|
|
|
|
runCommand
|
|
|
|
version
|
|
|
|
src
|
|
|
|
lib
|
|
|
|
stdenv
|
|
|
|
pkgs
|
|
|
|
pkgsi686Linux
|
|
|
|
pkgsStatic
|
|
|
|
nixosTests
|
|
|
|
self_attribute_name
|
|
|
|
;
|
|
|
|
nix = self;
|
2025-04-01 20:10:43 +02:00
|
|
|
};
|
2022-08-30 16:49:27 +02:00
|
|
|
};
|
|
|
|
|
2023-12-26 10:47:29 +00:00
|
|
|
# point 'nix edit' and ofborg at the file that defines the attribute,
|
|
|
|
# not this common file.
|
|
|
|
pos = builtins.unsafeGetAttrPos "version" args;
|
2022-01-24 23:07:22 -08:00
|
|
|
meta = with lib; {
|
|
|
|
description = "Powerful package manager that makes package management reliable and reproducible";
|
|
|
|
longDescription = ''
|
|
|
|
Nix is a powerful package manager for Linux and other Unix systems that
|
|
|
|
makes package management reliable and reproducible. It provides atomic
|
|
|
|
upgrades and rollbacks, side-by-side installation of multiple versions of
|
|
|
|
a package, multi-user package management and easy setup of build
|
|
|
|
environments.
|
|
|
|
'';
|
|
|
|
homepage = "https://nixos.org/";
|
2024-04-19 19:55:21 +08:00
|
|
|
license = licenses.lgpl21Plus;
|
2025-06-29 14:41:47 +02:00
|
|
|
inherit knownVulnerabilities maintainers teams;
|
2022-01-24 23:07:22 -08:00
|
|
|
platforms = platforms.unix;
|
|
|
|
outputsToInstall = [ "out" ] ++ optional enableDocumentation "man";
|
2023-07-31 21:49:41 +02:00
|
|
|
mainProgram = "nix";
|
2025-04-01 20:10:43 +02:00
|
|
|
};
|
2022-01-24 23:07:22 -08:00
|
|
|
};
|
2022-03-20 13:03:39 -04:00
|
|
|
in
|
|
|
|
self
|