Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

322 lines
7.8 KiB
Nix
Raw Permalink Normal View History

{
lib,
fetchFromGitHub,
version,
suffix ? "",
hash ? null,
src ? fetchFromGitHub {
owner = "NixOS";
repo = "nix";
rev = version;
inherit hash;
},
patches ? [ ],
knownVulnerabilities ? [ ],
maintainers ? [
lib.maintainers.lovesegfault
lib.maintainers.artturin
],
teams ? [ lib.teams.nix ],
self_attribute_name,
}@args:
assert (hash == null) -> (src != null);
let
atLeast225 = lib.versionAtLeast version "2.25pre";
in
2022-01-24 23:07:22 -08:00
{
stdenv,
autoconf-archive,
autoreconfHook,
bash,
bison,
boehmgc,
boost,
brotli,
busybox-sandbox-shell,
bzip2,
callPackage,
coreutils,
curl,
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,
libgit2,
2022-01-24 23:07:22 -08:00
libsodium,
libxml2,
libxslt,
2022-01-24 23:07:22 -08:00
lowdown,
lowdown-unsandboxed,
toml11,
2024-03-11 22:23:44 +01:00
man,
2022-01-24 23:07:22 -08:00
mdbook,
mdbook-linkcheck,
2022-01-24 23:07:22 -08:00
nlohmann_json,
nixosTests,
2022-01-24 23:07:22 -08:00
openssl,
perl,
python3,
2022-01-24 23:07:22 -08:00
pkg-config,
rapidcheck,
2022-01-24 23:07:22 -08:00
sqlite,
util-linuxMinimal,
xz,
enableDocumentation ? stdenv.buildPlatform.canExecute stdenv.hostPlatform,
2022-01-24 23:07:22 -08:00
enableStatic ? stdenv.hostPlatform.isStatic,
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,
# passthru tests
pkgsi686Linux,
pkgsStatic,
runCommand,
2024-08-17 12:30:27 +02:00
pkgs,
}:
let
self = stdenv.mkDerivation {
2022-01-24 23:07:22 -08:00
pname = "nix";
version = "${version}${suffix}";
VERSION_SUFFIX = suffix;
2022-01-24 23:07:22 -08:00
inherit src patches;
outputs = [
"out"
2022-01-24 23:07:22 -08:00
"dev"
]
++ lib.optionals enableDocumentation [
"man"
"doc"
2022-01-24 23:07:22 -08: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";
nativeInstallCheckInputs = [
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
bison
2024-12-10 06:33:10 +01:00
flex
jq
2024-12-10 06:33:10 +01:00
]
++ lib.optionals enableDocumentation [
(lib.getBin lowdown-unsandboxed)
mdbook
mdbook-linkcheck
]
++ lib.optionals stdenv.hostPlatform.isLinux [
2024-12-10 06:33:10 +01:00
util-linuxMinimal
2022-01-24 23:07:22 -08:00
];
buildInputs = [
boost
brotli
bzip2
curl
editline
2022-01-24 23:07:22 -08:00
libsodium
openssl
sqlite
xz
gtest
libarchive
lowdown
libgit2
toml11
2024-12-10 06:33:10 +01:00
rapidcheck
]
2024-12-10 06:33:10 +01:00
++ lib.optionals (atLeast225 && enableDocumentation) [
python3
]
++ lib.optionals (stdenv.hostPlatform.isx86_64) [
libcpuid
]
2022-01-24 23:07:22 -08:00
++ lib.optionals withLibseccomp [
libseccomp
]
2022-01-24 23:07:22 -08:00
++ lib.optionals withAWS [
aws-sdk-cpp
];
2022-01-24 23:07:22 -08:00
propagatedBuildInputs = [
boehmgc
nlohmann_json
];
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
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.*
''}
'';
2022-01-24 23:07:22 -08:00
configureFlags = [
"--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"
]
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"
]
++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isStatic) [
"--enable-embedded-sandbox-shell"
]
++
2022-01-24 23:07:22 -08:00
lib.optionals
(
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
)
[
2022-01-31 22:09:37 +00:00
"--with-system=${stdenv.hostPlatform.nix.system}"
]
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"
]
++ lib.optionals (stdenv.cc.isGNU && !enableStatic) [
"--enable-lto"
2022-01-31 22:09:37 +00:00
];
2022-01-24 23:07:22 -08: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 = [
# 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.
"--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;
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 =
lib.optionalString stdenv.hostPlatform.isDarwin ''
2024-12-10 06:33:10 +01:00
export TMPDIR=$NIX_BUILD_TOP
''
2024-12-10 06:33:10 +01:00
# Prevent crashes in libcurl due to invoking Objective-C `+initialize` methods after `fork`.
# 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
''
2024-12-10 06:33:10 +01:00
# See https://github.com/NixOS/nix/issues/5687
+ lib.optionalString (stdenv.hostPlatform.isDarwin) ''
2024-12-10 06:33:10 +01:00
echo "exit 99" > tests/gc-non-blocking.sh
'' # TODO: investigate why this broken
+ lib.optionalString (stdenv.hostPlatform.system == "aarch64-linux") ''
echo "exit 0" > tests/functional/flakes/show.sh
''
+ ''
2024-12-10 06:33:10 +01:00
# nixStatic otherwise does not find its man pages in tests.
export MANPATH=$man/share/man:$MANPATH
2024-12-10 06:33:10 +01:00
'';
2022-01-24 23:07:22 -08:00
separateDebugInfo = stdenv.hostPlatform.isLinux && !enableStatic;
2022-01-24 23:07:22 -08:00
enableParallelBuilding = true;
passthru = {
inherit aws-sdk-cpp boehmgc;
perl-bindings = perl.pkgs.toPerlModule (
callPackage ./nix-perl.nix {
nix = self;
}
);
tests = import ./tests.nix {
inherit
runCommand
version
src
lib
stdenv
pkgs
pkgsi686Linux
pkgsStatic
nixosTests
self_attribute_name
;
nix = self;
};
};
# 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/";
license = licenses.lgpl21Plus;
inherit knownVulnerabilities maintainers teams;
2022-01-24 23:07:22 -08:00
platforms = platforms.unix;
outputsToInstall = [ "out" ] ++ optional enableDocumentation "man";
mainProgram = "nix";
};
2022-01-24 23:07:22 -08:00
};
in
self