nix-super/package.nix

264 lines
6.7 KiB
Nix
Raw Normal View History

2023-12-01 00:48:44 +02: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
2023-12-03 19:47:07 +02:00
# Configuration Options
#
# This probably seems like too many degrees of freedom, but it
# faithfully reflects how the underlying configure + make build system
# work. The top-level flake.nix will choose useful combinations.
# Whether to install unit tests. This is useful when cross compiling
# since we cannot run them natively during the build, but can do so
# later.
, installUnitTests ? stdenv.hostPlatform != stdenv.buildPlatform
2023-12-01 00:48:44 +02:00
}:
let
version = lib.fileContents ./.version + versionSuffix;
canRunInstalled = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
2023-12-02 19:25:47 +02: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-12-01 00:48:44 +02:00
in
2023-12-03 19:47:07 +02:00
stdenv.mkDerivation (finalAttrs: let
# Either running the unit tests during the build, or installing them
# to be run later, requiresthe unit tests to be built.
buildUnitTests = finalAttrs.doCheck || installUnitTests;
in {
2023-12-01 13:25:22 +02:00
pname = "nix";
2023-12-01 00:48:44 +02:00
inherit version;
src =
let
in
fileset.toSource {
root = ./.;
2023-12-02 19:25:47 +02:00
fileset = fileset.intersect filesets.baseFiles (fileset.unions [
filesets.configureFiles
filesets.topLevelBuildFiles
2023-12-01 00:48:44 +02:00
./boehmgc-coroutine-sp-fallback.diff
./doc
./misc
./precompiled-headers.h
./src
./unit-test-data
./COPYING
./scripts/local.mk
2023-12-02 19:25:47 +02:00
filesets.functionalTestFiles
2023-12-01 00:48:44 +02:00
]);
};
VERSION_SUFFIX = versionSuffix;
outputs = [ "out" "dev" "doc" ]
2023-12-03 19:47:07 +02:00
++ lib.optional installUnitTests "check";
2023-12-01 00:48:44 +02:00
nativeBuildInputs = [
bison
flex
(lib.getBin lowdown)
2023-12-01 13:25:22 +02:00
jq # Also for custom mdBook preprocessor.
2023-12-01 00:48:44 +02: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 18:08:06 +02:00
# These could be checkInputs but the configure phase fails w/o them
gtest
rapidcheck
2023-12-01 00:48:44 +02:00
]
2023-12-01 13:25:22 +02:00
++ lib.optional stdenv.isLinux libseccomp
2023-12-01 00:48:44 +02:00
++ lib.optional stdenv.hostPlatform.isx86_64 libcpuid
# There have been issues building these dependencies
2023-12-01 13:25:22 +02:00
++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform && (stdenv.isLinux || stdenv.isDarwin))
2023-12-01 00:48:44 +02:00
(aws-sdk-cpp.override {
apis = ["s3" "transfer"];
customMemoryManagement = false;
2023-12-01 13:25:22 +02:00
})
;
2023-12-03 19:47:07 +02:00
doCheck = stdenv.hostPlatform != stdenv.buildPlatform;
2023-12-01 13:25:22 +02:00
checkInputs = [
2023-12-02 18:08:06 +02:00
# see buildInputs. The configure script always wants its test libs
2023-12-01 00:49:02 +02:00
];
2023-12-01 00:48:44 +02:00
2023-12-01 13:25:22 +02:00
nativeCheckInputs = [
git
2023-12-02 18:08:06 +02:00
mercurial
openssh
2023-12-01 13:25:22 +02:00
];
2023-12-01 00:48:44 +02:00
propagatedBuildInputs = [
boehmgc
nlohmann_json
];
disallowedReferences = [ boost ];
2023-12-01 13:25:22 +02: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-12-01 00:48:44 +02:00
configureFlags =
lib.optionals stdenv.isLinux [
"--with-boost=${boost}/lib"
"--with-sandbox-shell=${sh}/bin/busybox"
]
2023-12-01 13:25:22 +02:00
++ lib.optional (stdenv.isLinux && !(stdenv.hostPlatform.isStatic && stdenv.system == "aarch64-linux"))
2023-12-01 00:48:44 +02:00
"LDFLAGS=-fuse-ld=gold"
++ [ "--sysconfdir=/etc" ]
++ lib.optional stdenv.hostPlatform.isStatic "--enable-embedded-sandbox-shell"
2023-12-03 19:47:07 +02:00
++ lib.optional buildUnitTests "RAPIDCHECK_HEADERS=${lib.getDev rapidcheck}/extras/gtest/include"
++ lib.optionals installUnitTests [
"--enable-install-unit-tests"
"--with-check-bin-dir=${builtins.placeholder "check"}/bin"
"--with-check-lib-dir=${builtins.placeholder "check"}/lib"
]
2023-12-01 00:48:44 +02: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 19:25:47 +02:00
passthru ={
inherit filesets;
perl-bindings = callPackage ./perl {
inherit fileset stdenv;
};
2023-12-01 00:48:44 +02:00
};
meta.platforms = lib.platforms.unix;
meta.mainProgram = "nix";
})