core/pkgs/by-name/li/lix/common.nix

300 lines
8.1 KiB
Nix
Raw Permalink Normal View History

2024-08-17 16:39:28 +00:00
{
lib,
fetchFromGitHub,
version,
suffix ? "",
hash ? null,
src ? fetchFromGitHub {
2024-05-02 00:46:19 +00:00
owner = "lix-project";
repo = "lix";
rev = version;
inherit hash;
2024-08-17 16:39:28 +00:00
},
docCargoHash ? null,
docCargoLock ? null,
patches ? [ ],
maintainers ? lib.teams.lix.members,
2024-05-02 00:46:19 +00:00
}@args:
assert (hash == null) -> (src != null);
2024-08-17 16:39:28 +00:00
assert lib.assertMsg (docCargoHash != null || docCargoLock != null)
"Either `lix-doc`'s cargoHash using `docCargoHash` or `lix-doc`'s `cargoLock.lockFile` using `docCargoLock` must be set!";
let
isLegacyParser = lib.versionOlder version "2.91";
in
{
stdenv,
meson,
bison,
boehmgc,
boost,
brotli,
busybox-sandbox-shell,
bzip2,
callPackage,
curl,
cmake,
doxygen,
editline,
flex,
git,
gtest,
jq,
lib,
libarchive,
libcpuid,
libsodium,
lowdown,
lsof,
mercurial,
mdbook,
mdbook-linkcheck,
nlohmann_json,
ninja,
openssl,
toml11,
pegtl,
python3,
pkg-config,
rapidcheck,
Security,
sqlite,
util-linuxMinimal,
xz,
# , nixosTests
enableDocumentation ? stdenv.hostPlatform == stdenv.buildPlatform,
enableStatic ? stdenv.hostPlatform.isStatic,
withAWS ? !enableStatic && (stdenv.isLinux || stdenv.isDarwin),
aws-sdk-cpp,
# RISC-V support in progress https://github.com/seccomp/libseccomp/pull/50
withLibseccomp ? lib.meta.availableOn stdenv.hostPlatform libseccomp,
libseccomp,
confDir,
stateDir,
storeDir,
2024-05-02 00:46:19 +00:00
}:
let
lix-doc = callPackage ./doc {
inherit src;
version = "${version}${suffix}";
cargoHash = docCargoHash;
};
self = stdenv.mkDerivation {
pname = "lix";
version = "${version}${suffix}";
VERSION_SUFFIX = suffix;
inherit src patches;
outputs =
[
"out"
"dev"
]
++ lib.optionals enableDocumentation [
"man"
"doc"
];
strictDeps = true;
nativeBuildInputs =
[
pkg-config
flex
jq
meson
ninja
cmake
python3
# Tests
git
mercurial
jq
lsof
]
2024-08-17 16:39:28 +00:00
++ lib.optionals isLegacyParser [ bison ]
++ lib.optionals enableDocumentation [
2024-05-02 00:46:19 +00:00
(lib.getBin lowdown)
mdbook
mdbook-linkcheck
2024-08-17 16:39:28 +00:00
doxygen
2024-05-02 00:46:19 +00:00
]
++ lib.optionals stdenv.isLinux [ util-linuxMinimal ];
buildInputs =
[
boost
brotli
bzip2
curl
editline
libsodium
openssl
sqlite
xz
gtest
libarchive
lowdown
rapidcheck
toml11
lix-doc
]
2024-08-17 16:39:28 +00:00
++ lib.optionals (!isLegacyParser) [ pegtl ]
2024-05-02 00:46:19 +00:00
++ lib.optionals stdenv.isDarwin [ Security ]
2024-08-17 16:39:28 +00:00
++ lib.optionals stdenv.isx86_64 [ libcpuid ]
2024-05-02 00:46:19 +00:00
++ lib.optionals withLibseccomp [ libseccomp ]
++ lib.optionals withAWS [ aws-sdk-cpp ];
propagatedBuildInputs = [
boehmgc
nlohmann_json
];
postPatch = ''
2024-08-17 16:39:28 +00:00
patchShebangs --build tests doc/manual
2024-05-02 00:46:19 +00:00
'';
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
rm -f $out/lib/*.a
${lib.optionalString stdenv.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
''}
'';
mesonFlags =
[
2024-08-17 16:39:28 +00:00
(lib.mesonBool "b_lto" true)
2024-05-02 00:46:19 +00:00
(lib.mesonEnable "gc" true)
(lib.mesonBool "enable-tests" true)
(lib.mesonBool "enable-docs" enableDocumentation)
(lib.mesonBool "enable-embedded-sandbox-shell" (stdenv.isLinux && stdenv.hostPlatform.isStatic))
(lib.mesonEnable "seccomp-sandboxing" withLibseccomp)
(lib.mesonOption "store-dir" storeDir)
(lib.mesonOption "state-dir" stateDir)
(lib.mesonOption "sysconfdir" confDir)
]
++ lib.optionals stdenv.isLinux [
(lib.mesonOption "sandbox-shell" "${busybox-sandbox-shell}/bin/busybox")
];
# Needed for Meson to find Boost.
# https://github.com/NixOS/nixpkgs/issues/86131.
env = {
BOOST_INCLUDEDIR = "${lib.getDev boost}/include";
BOOST_LIBRARYDIR = "${lib.getLib boost}/lib";
};
2024-08-17 16:39:28 +00:00
ninjaFlags = [ "-v" ];
2024-05-02 00:46:19 +00:00
postInstall =
2024-08-17 16:39:28 +00:00
lib.optionalString enableDocumentation ''
2024-05-02 00:46:19 +00:00
mkdir -p $doc/nix-support
echo "doc manual $doc/share/doc/nix/manual" >> $doc/nix-support/hydra-build-products
2024-08-17 16:39:28 +00:00
mkdir -p $devdoc/nix-support
echo "devdoc internal-api $devdoc/share/doc/nix/internal-api" >> $devdoc/nix-support/hydra-build-products
2024-05-02 00:46:19 +00:00
''
+ 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 ''
for lib in libnixutil.dylib libnixexpr.dylib; do
install_name_tool \
-change "${lib.getLib boost}/lib/libboost_context.dylib" \
"$out/lib/libboost_context.dylib" \
"$out/lib/$lib"
done
'';
doCheck = true;
2024-08-17 16:39:28 +00:00
mesonCheckFlags = [
"--suite=check"
"--print-errorlogs"
];
2024-05-02 00:46:19 +00:00
checkInputs = [
gtest
rapidcheck
];
2024-08-17 16:39:28 +00:00
# This needs to run after _multioutDocs moves the docs to $doc
postFixup = ''
mkdir -p $devdoc/share/doc/nix
mv $doc/share/doc/nix/internal-api $devdoc/share/doc/nix
'';
2024-05-02 00:46:19 +00:00
doInstallCheck = true;
2024-08-17 16:39:28 +00:00
mesonInstallCheckFlags = [
"--suite=installcheck"
"--print-errorlogs"
];
2024-05-02 00:46:19 +00:00
preInstallCheck = lib.optionalString stdenv.hostPlatform.isDarwin ''
# socket path becomes too long otherwise
export TMPDIR=$NIX_BUILD_TOP
# 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.
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
'';
installCheckPhase = ''
runHook preInstallCheck
flagsArray=($mesonInstallCheckFlags "''${mesonInstallCheckFlagsArray[@]}")
meson test --no-rebuild "''${flagsArray[@]}"
runHook postInstallCheck
'';
# strictoverflow is disabled because we trap on signed overflow instead
hardeningDisable = [ "strictoverflow" ] ++ lib.optional stdenv.hostPlatform.isStatic "pie";
# hardeningEnable = lib.optionals (!stdenv.isDarwin) [ "pie" ];
# hardeningDisable = lib.optional stdenv.hostPlatform.isMusl "fortify";
separateDebugInfo = stdenv.isLinux && !enableStatic;
enableParallelBuilding = true;
passthru = {
inherit aws-sdk-cpp boehmgc;
# tests = {
# misc = nixosTests.misc.lix.passthru.override { nixPackage = self; };
# };
};
# point 'nix edit' and ofborg at the file that defines the attribute,
# not this common file.
pos = builtins.unsafeGetAttrPos "version" args;
2024-08-17 16:39:28 +00:00
meta = {
2024-05-02 00:46:19 +00:00
description = "Powerful package manager that makes package management reliable and reproducible";
longDescription = ''
Lix (a fork of 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://lix.systems";
2024-08-17 16:39:28 +00:00
license = lib.licenses.lgpl21Plus;
2024-05-02 00:46:19 +00:00
inherit maintainers;
2024-08-17 16:39:28 +00:00
platforms = lib.platforms.unix;
outputsToInstall = [ "out" ] ++ lib.optional enableDocumentation "man";
2024-05-02 00:46:19 +00:00
mainProgram = "nix";
broken = enableStatic;
};
};
in
self