Nix/package.nix

249 lines
6.2 KiB
Nix
Raw Normal View History

2023-11-30 23:48:44 +01:00
{ lib
, callPackage
, stdenv
, versionSuffix ? ""
, officialRelease ? false
, buildUnreleasedNotes ? false
, autoconf-archive
, autoreconfHook
, aws-sdk-cpp
, boehmgc
, nlohmann_json
, bison
, boost
, brotli
, bzip2
, changelog-d
, curl
, editline
, fileset
, flex
, git
, gtest
, jq
, libarchive
, libcpuid
, libgit2
, libseccomp
, libsodium
, lowdown
, mdbook
, mdbook-linkcheck
, mercurial
, openssh
, openssl
, pkg-config
, rapidcheck
, sh
, sqlite
, util-linux
, xz
}:
let
version = lib.fileContents ./.version + versionSuffix;
canRunInstalled = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
2023-12-02 18:25:47 +01:00
filesets = {
baseFiles = fileset.fileFilter (f: f.name != ".gitignore") ./.;
configureFiles = fileset.unions [
./.version
./configure.ac
./m4
# TODO: do we really need README.md? It doesn't seem used in the build.
./README.md
];
topLevelBuildFiles = fileset.unions [
./local.mk
./Makefile
./Makefile.config.in
./mk
];
functionalTestFiles = fileset.unions [
./tests/functional
(fileset.fileFilter (f: lib.strings.hasPrefix "nix-profile" f.name) ./scripts)
];
};
2023-11-30 23:48:44 +01:00
in
stdenv.mkDerivation (finalAttrs: {
2023-12-01 12:25:22 +01:00
pname = "nix";
2023-11-30 23:48:44 +01:00
inherit version;
src =
let
in
fileset.toSource {
root = ./.;
2023-12-02 18:25:47 +01:00
fileset = fileset.intersect filesets.baseFiles (fileset.unions [
filesets.configureFiles
filesets.topLevelBuildFiles
2023-11-30 23:48:44 +01:00
./boehmgc-coroutine-sp-fallback.diff
./doc
./misc
./precompiled-headers.h
./src
./unit-test-data
./COPYING
./scripts/local.mk
2023-12-02 18:25:47 +01:00
filesets.functionalTestFiles
2023-11-30 23:48:44 +01:00
]);
};
VERSION_SUFFIX = versionSuffix;
outputs = [ "out" "dev" "doc" ]
++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) "check";
nativeBuildInputs = [
bison
flex
(lib.getBin lowdown)
2023-12-01 12:25:22 +01:00
jq # Also for custom mdBook preprocessor.
2023-11-30 23:48:44 +01:00
mdbook
mdbook-linkcheck
autoconf-archive
autoreconfHook
pkg-config
]
++ lib.optional stdenv.hostPlatform.isLinux util-linux
# Official releases don't have rl-next, so we don't need to compile a changelog
++ lib.optional (!officialRelease && buildUnreleasedNotes) changelog-d;
buildInputs = [
boost
brotli
bzip2
curl
editline
libarchive
libgit2
libsodium
lowdown
openssl
sqlite
xz
2023-12-02 17:08:06 +01:00
# These could be checkInputs but the configure phase fails w/o them
gtest
rapidcheck
2023-11-30 23:48:44 +01:00
]
2023-12-01 12:25:22 +01:00
++ lib.optional stdenv.isLinux libseccomp
2023-11-30 23:48:44 +01:00
++ lib.optional stdenv.hostPlatform.isx86_64 libcpuid
# There have been issues building these dependencies
2023-12-01 12:25:22 +01:00
++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform && (stdenv.isLinux || stdenv.isDarwin))
2023-11-30 23:48:44 +01:00
(aws-sdk-cpp.override {
apis = ["s3" "transfer"];
customMemoryManagement = false;
2023-12-01 12:25:22 +01:00
})
;
doCheck = true;
checkInputs = [
2023-12-02 17:08:06 +01:00
# see buildInputs. The configure script always wants its test libs
2023-11-30 23:49:02 +01:00
];
2023-11-30 23:48:44 +01:00
2023-12-01 12:25:22 +01:00
nativeCheckInputs = [
git
2023-12-02 17:08:06 +01:00
mercurial
openssh
2023-12-01 12:25:22 +01:00
];
2023-11-30 23:48:44 +01:00
propagatedBuildInputs = [
boehmgc
nlohmann_json
];
disallowedReferences = [ boost ];
2023-12-01 12:25:22 +01:00
preConfigure = lib.optionalString (! stdenv.hostPlatform.isStatic) ''
# Copy libboost_context so we don't get all of Boost in our closure.
# https://github.com/NixOS/nixpkgs/issues/45462
mkdir -p $out/lib
cp -pd ${boost}/lib/{libboost_context*,libboost_thread*,libboost_system*,libboost_regex*} $out/lib
rm -f $out/lib/*.a
${lib.optionalString stdenv.hostPlatform.isLinux ''
chmod u+w $out/lib/*.so.*
patchelf --set-rpath $out/lib:${stdenv.cc.cc.lib}/lib $out/lib/libboost_thread.so.*
''}
${lib.optionalString stdenv.hostPlatform.isDarwin ''
for LIB in $out/lib/*.dylib; do
chmod u+w $LIB
install_name_tool -id $LIB $LIB
install_name_tool -delete_rpath ${boost}/lib/ $LIB || true
done
install_name_tool -change ${boost}/lib/libboost_system.dylib $out/lib/libboost_system.dylib $out/lib/libboost_thread.dylib
''}
'';
2023-11-30 23:48:44 +01:00
configureFlags =
lib.optionals stdenv.isLinux [
"--with-boost=${boost}/lib"
"--with-sandbox-shell=${sh}/bin/busybox"
]
2023-12-01 12:25:22 +01:00
++ lib.optional (stdenv.isLinux && !(stdenv.hostPlatform.isStatic && stdenv.system == "aarch64-linux"))
2023-11-30 23:48:44 +01:00
"LDFLAGS=-fuse-ld=gold"
++ [ "--sysconfdir=/etc" ]
++ lib.optional stdenv.hostPlatform.isStatic "--enable-embedded-sandbox-shell"
++ [ (lib.enableFeature finalAttrs.doCheck "tests") ]
2023-12-01 12:25:22 +01:00
++ lib.optionals finalAttrs.doCheck (
[ "RAPIDCHECK_HEADERS=${lib.getDev rapidcheck}/extras/gtest/include" ]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"--enable-install-unit-tests"
"--with-check-bin-dir=${builtins.placeholder "check"}/bin"
"--with-check-lib-dir=${builtins.placeholder "check"}/lib"
])
2023-11-30 23:48:44 +01:00
++ lib.optional (!canRunInstalled) "--disable-doc-gen";
enableParallelBuilding = true;
makeFlags = "profiledir=$(out)/etc/profile.d PRECOMPILE_HEADERS=1";
installFlags = "sysconfdir=$(out)/etc";
postInstall = ''
mkdir -p $doc/nix-support
echo "doc manual $doc/share/doc/nix/manual" >> $doc/nix-support/hydra-build-products
${lib.optionalString stdenv.hostPlatform.isStatic ''
mkdir -p $out/nix-support
echo "file binary-dist $out/bin/nix" >> $out/nix-support/hydra-build-products
''}
${lib.optionalString stdenv.isDarwin ''
install_name_tool \
-change ${boost}/lib/libboost_context.dylib \
$out/lib/libboost_context.dylib \
$out/lib/libnixutil.dylib
install_name_tool \
-change ${boost}/lib/libboost_regex.dylib \
$out/lib/libboost_regex.dylib \
$out/lib/libnixexpr.dylib
''}
'';
doInstallCheck = finalAttrs.doCheck;
installCheckFlags = "sysconfdir=$(out)/etc";
installCheckTarget = "installcheck"; # work around buggy detection in stdenv
separateDebugInfo = !stdenv.hostPlatform.isStatic;
strictDeps = true;
hardeningDisable = lib.optional stdenv.hostPlatform.isStatic "pie";
2023-12-02 18:25:47 +01:00
passthru ={
inherit filesets;
perl-bindings = callPackage ./perl {
inherit fileset stdenv;
};
2023-11-30 23:48:44 +01:00
};
meta.platforms = lib.platforms.unix;
meta.mainProgram = "nix";
})