2021-01-09 10:05:03 +00:00
|
|
|
{ lib, fetchurl, fetchFromGitHub, fetchpatch, callPackage
|
2020-04-24 23:36:52 +00:00
|
|
|
, storeDir ? "/nix/store"
|
|
|
|
, stateDir ? "/nix/var"
|
|
|
|
, confDir ? "/etc"
|
|
|
|
, boehmgc
|
2021-02-05 17:12:51 +00:00
|
|
|
, Security
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
common =
|
2021-01-09 10:05:03 +00:00
|
|
|
{ lib, stdenv, perl, curl, bzip2, sqlite, openssl ? null, xz
|
2021-03-20 04:20:00 +00:00
|
|
|
, bash, coreutils, util-linuxMinimal, gzip, gnutar
|
2021-04-12 18:23:04 +00:00
|
|
|
, pkg-config, boehmgc, libsodium, brotli, boost, editline, nlohmann_json
|
2020-10-27 00:29:36 +00:00
|
|
|
, autoreconfHook, autoconf-archive, bison, flex
|
2021-03-12 07:09:13 +00:00
|
|
|
, jq, libarchive, libcpuid
|
2020-10-27 00:29:36 +00:00
|
|
|
, lowdown, mdbook
|
2020-05-15 21:57:56 +00:00
|
|
|
# Used by tests
|
2021-04-05 15:23:46 +00:00
|
|
|
, gtest
|
2020-04-24 23:36:52 +00:00
|
|
|
, busybox-sandbox-shell
|
|
|
|
, storeDir
|
|
|
|
, stateDir
|
|
|
|
, confDir
|
2021-05-20 23:08:51 +00:00
|
|
|
, withLibseccomp ? lib.meta.availableOn stdenv.hostPlatform libseccomp, libseccomp
|
2021-03-09 03:18:52 +00:00
|
|
|
, withAWS ? !enableStatic && (stdenv.isLinux || stdenv.isDarwin), aws-sdk-cpp
|
2021-01-05 17:05:55 +00:00
|
|
|
, enableStatic ? stdenv.hostPlatform.isStatic
|
2021-06-28 23:13:55 +00:00
|
|
|
, enableDocumentation ? lib.versionOlder version "2.4pre" ||
|
|
|
|
stdenv.hostPlatform == stdenv.buildPlatform
|
2021-04-13 19:44:15 +00:00
|
|
|
, pname, version, suffix ? "", src
|
2021-01-09 10:05:03 +00:00
|
|
|
, patches ? [ ]
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
let
|
|
|
|
sh = busybox-sandbox-shell;
|
|
|
|
nix = stdenv.mkDerivation rec {
|
2021-04-13 19:44:15 +00:00
|
|
|
inherit pname version src patches;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-11-03 02:18:15 +00:00
|
|
|
is24 = lib.versionAtLeast version "2.4pre";
|
2021-12-19 01:06:50 +00:00
|
|
|
is25 = lib.versionAtLeast version "2.5pre";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
VERSION_SUFFIX = suffix;
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
outputs =
|
|
|
|
[ "out" "dev" ]
|
|
|
|
++ lib.optionals enableDocumentation [ "man" "doc" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-08-05 21:33:18 +00:00
|
|
|
hardeningEnable = [ "pie" ];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
nativeBuildInputs =
|
2021-02-05 17:12:51 +00:00
|
|
|
[ pkg-config ]
|
2021-04-05 15:23:46 +00:00
|
|
|
++ lib.optionals stdenv.isLinux [ util-linuxMinimal ]
|
2021-06-28 23:13:55 +00:00
|
|
|
++ lib.optionals (is24 && enableDocumentation) [
|
|
|
|
(lib.getBin lowdown) mdbook
|
|
|
|
]
|
2020-11-03 02:18:15 +00:00
|
|
|
++ lib.optionals is24
|
2020-10-27 00:29:36 +00:00
|
|
|
[ autoreconfHook
|
|
|
|
autoconf-archive
|
|
|
|
bison flex
|
|
|
|
jq
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
buildInputs =
|
2021-12-06 16:07:01 +00:00
|
|
|
[ curl libsodium openssl sqlite xz bzip2
|
2020-04-24 23:36:52 +00:00
|
|
|
brotli boost editline
|
|
|
|
]
|
2021-02-05 17:12:51 +00:00
|
|
|
++ lib.optionals stdenv.isDarwin [ Security ]
|
2021-04-05 15:23:46 +00:00
|
|
|
++ lib.optionals is24 [ libarchive gtest lowdown ]
|
2021-03-15 08:37:03 +00:00
|
|
|
++ lib.optional (is24 && stdenv.isx86_64) libcpuid
|
2020-04-24 23:36:52 +00:00
|
|
|
++ lib.optional withLibseccomp libseccomp
|
|
|
|
++ lib.optional withAWS
|
|
|
|
((aws-sdk-cpp.override {
|
|
|
|
apis = ["s3" "transfer"];
|
|
|
|
customMemoryManagement = false;
|
|
|
|
}).overrideDerivation (args: {
|
2021-01-09 10:05:03 +00:00
|
|
|
patches = args.patches or [] ++ [
|
|
|
|
./aws-sdk-cpp-TransferManager-ContentEncoding.patch
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
propagatedBuildInputs = [ boehmgc ];
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
NIX_LDFLAGS = lib.optionals (!is24) [
|
2020-06-18 07:06:33 +00:00
|
|
|
# https://github.com/NixOS/nix/commit/3e85c57a6cbf46d5f0fe8a89b368a43abd26daba
|
2021-12-06 16:07:01 +00:00
|
|
|
(lib.optionalString enableStatic "-lssl -lbrotlicommon -lssh2 -lz -lnghttp2 -lcrypto")
|
2020-06-18 07:06:33 +00:00
|
|
|
# https://github.com/NixOS/nix/commits/74b4737d8f0e1922ef5314a158271acf81cd79f8
|
2021-12-06 16:07:01 +00:00
|
|
|
(lib.optionalString (stdenv.hostPlatform.system == "armv5tel-linux" || stdenv.hostPlatform.system == "armv6l-linux") "-latomic")
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
preConfigure =
|
|
|
|
# Copy libboost_context so we don't get all of Boost in our closure.
|
|
|
|
# https://github.com/NixOS/nixpkgs/issues/45462
|
2020-06-18 07:06:33 +00:00
|
|
|
lib.optionalString (!enableStatic) ''
|
2020-04-24 23:36:52 +00:00
|
|
|
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.*
|
|
|
|
''}
|
|
|
|
'' +
|
2021-06-28 23:13:55 +00:00
|
|
|
# On all versions before c9f51e87057652db0013289a95deffba495b35e7, which
|
|
|
|
# removes config.nix entirely and is not present in 2.3.x, we need to
|
|
|
|
# patch around an issue where the Nix configure step pulls in the build
|
|
|
|
# system's bash and other utilities when cross-compiling.
|
2021-01-05 17:05:55 +00:00
|
|
|
lib.optionalString (
|
2021-06-28 23:13:55 +00:00
|
|
|
stdenv.buildPlatform != stdenv.hostPlatform && !is24
|
2021-01-05 17:05:55 +00:00
|
|
|
) ''
|
2020-04-24 23:36:52 +00:00
|
|
|
mkdir tmp/
|
|
|
|
substitute corepkgs/config.nix.in tmp/config.nix.in \
|
|
|
|
--subst-var-by bash ${bash}/bin/bash \
|
|
|
|
--subst-var-by coreutils ${coreutils}/bin \
|
|
|
|
--subst-var-by bzip2 ${bzip2}/bin/bzip2 \
|
|
|
|
--subst-var-by gzip ${gzip}/bin/gzip \
|
|
|
|
--subst-var-by xz ${xz}/bin/xz \
|
|
|
|
--subst-var-by tar ${gnutar}/bin/tar \
|
|
|
|
--subst-var-by tr ${coreutils}/bin/tr
|
|
|
|
mv tmp/config.nix.in corepkgs/config.nix.in
|
|
|
|
'';
|
|
|
|
|
|
|
|
configureFlags =
|
|
|
|
[ "--with-store-dir=${storeDir}"
|
|
|
|
"--localstatedir=${stateDir}"
|
|
|
|
"--sysconfdir=${confDir}"
|
|
|
|
"--enable-gc"
|
|
|
|
]
|
2021-06-28 23:13:55 +00:00
|
|
|
++ lib.optional (!enableDocumentation) "--disable-doc-gen"
|
2021-06-04 09:07:49 +00:00
|
|
|
++ lib.optionals (!is24) [
|
|
|
|
# option was removed in 2.4
|
|
|
|
"--disable-init-state"
|
|
|
|
]
|
2020-04-24 23:36:52 +00:00
|
|
|
++ lib.optionals stdenv.isLinux [
|
|
|
|
"--with-sandbox-shell=${sh}/bin/busybox"
|
|
|
|
]
|
|
|
|
++ lib.optional (
|
|
|
|
stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform ? nix && stdenv.hostPlatform.nix ? system
|
2021-02-05 17:12:51 +00:00
|
|
|
) "--with-system=${stdenv.hostPlatform.nix.system}"
|
2020-04-24 23:36:52 +00:00
|
|
|
# RISC-V support in progress https://github.com/seccomp/libseccomp/pull/50
|
|
|
|
++ lib.optional (!withLibseccomp) "--disable-seccomp-sandboxing";
|
|
|
|
|
2020-07-18 16:06:22 +00:00
|
|
|
makeFlags = [ "profiledir=$(out)/etc/profile.d" ]
|
|
|
|
++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) "PRECOMPILE_HEADERS=0";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
installFlags = [ "sysconfdir=$(out)/etc" ];
|
|
|
|
|
|
|
|
doInstallCheck = true; # not cross
|
|
|
|
|
|
|
|
# socket path becomes too long otherwise
|
2021-03-20 04:20:00 +00:00
|
|
|
preInstallCheck = lib.optionalString stdenv.isDarwin ''
|
2020-04-24 23:36:52 +00:00
|
|
|
export TMPDIR=$NIX_BUILD_TOP
|
2021-12-19 01:06:50 +00:00
|
|
|
''
|
|
|
|
# See https://github.com/NixOS/nix/issues/5687
|
|
|
|
+ lib.optionalString (is25 && stdenv.isDarwin) ''
|
|
|
|
echo "exit 99" > tests/gc-non-blocking.sh
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
separateDebugInfo = stdenv.isLinux && (is24 -> !enableStatic);
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
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/";
|
2021-12-06 16:07:01 +00:00
|
|
|
license = licenses.lgpl2Plus;
|
|
|
|
maintainers = with maintainers; [ eelco lovesegfault ];
|
|
|
|
platforms = platforms.unix;
|
|
|
|
outputsToInstall = [ "out" ] ++ optional enableDocumentation "man";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
passthru = {
|
2021-04-12 18:23:04 +00:00
|
|
|
perl-bindings = perl.pkgs.toPerlModule (stdenv.mkDerivation {
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "nix-perl";
|
|
|
|
inherit version;
|
|
|
|
|
|
|
|
inherit src;
|
|
|
|
|
|
|
|
postUnpack = "sourceRoot=$sourceRoot/perl";
|
|
|
|
|
|
|
|
# This is not cross-compile safe, don't have time to fix right now
|
|
|
|
# but noting for future travellers.
|
|
|
|
nativeBuildInputs =
|
2021-02-05 17:12:51 +00:00
|
|
|
[ perl pkg-config curl nix libsodium boost autoreconfHook autoconf-archive nlohmann_json ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
configureFlags =
|
2021-04-12 18:23:04 +00:00
|
|
|
[ "--with-dbi=${perl.pkgs.DBI}/${perl.libPrefix}"
|
|
|
|
"--with-dbd-sqlite=${perl.pkgs.DBDSQLite}/${perl.libPrefix}"
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
preConfigure = "export NIX_STATE_DIR=$TMPDIR";
|
|
|
|
|
|
|
|
preBuild = "unset NIX_INDENT_MAKE";
|
2021-04-12 18:23:04 +00:00
|
|
|
});
|
2021-07-21 07:28:18 +00:00
|
|
|
inherit boehmgc;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in nix;
|
|
|
|
|
2021-07-21 07:28:18 +00:00
|
|
|
boehmgc_nix = boehmgc.override {
|
|
|
|
enableLargeConfig = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
boehmgc_nixUnstable = boehmgc_nix.overrideAttrs (drv: {
|
|
|
|
patches = (drv.patches or []) ++ [
|
|
|
|
# Part of the GC solution in https://github.com/NixOS/nix/pull/4944
|
|
|
|
(fetchpatch {
|
2021-10-28 06:52:43 +00:00
|
|
|
url = "https://github.com/hercules-ci/nix/raw/5c58d84a76d96f269e3ff1e72c9c9ba5f68576af/boehmgc-coroutine-sp-fallback.diff";
|
2021-07-21 07:28:18 +00:00
|
|
|
sha256 = "sha256-JvnWVTlkltmQUs/0qApv/LPZ690UX1/2hEP+LYRwKbI=";
|
|
|
|
})
|
|
|
|
];
|
|
|
|
});
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
# master: https://github.com/NixOS/nix/pull/5536
|
|
|
|
# 2.4: https://github.com/NixOS/nix/pull/5537
|
|
|
|
installNlohmannJsonPatch = fetchpatch {
|
|
|
|
url = "https://github.com/NixOS/nix/pull/5536.diff";
|
|
|
|
sha256 = "sha256-SPnam4xNIjbMgnq6IP1AaM1V62X0yZNo4DEVmI8sHOo=";
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
in rec {
|
|
|
|
|
|
|
|
nix = nixStable;
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
nixStable = nix_2_4;
|
|
|
|
|
|
|
|
nix_2_3 = callPackage common (rec {
|
2021-04-13 19:44:15 +00:00
|
|
|
pname = "nix";
|
2021-10-08 15:17:17 +00:00
|
|
|
version = "2.3.16";
|
2020-04-24 23:36:52 +00:00
|
|
|
src = fetchurl {
|
2021-04-13 19:44:15 +00:00
|
|
|
url = "https://nixos.org/releases/nix/${pname}-${version}/${pname}-${version}.tar.xz";
|
2021-10-08 15:17:17 +00:00
|
|
|
sha256 = "sha256-fuaBtp8FtSVJLSAsO+3Nne4ZYLuBj2JpD2xEk7fCqrw=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-07-21 07:28:18 +00:00
|
|
|
boehmgc = boehmgc_nix;
|
|
|
|
|
|
|
|
inherit storeDir stateDir confDir;
|
2020-04-24 23:36:52 +00:00
|
|
|
});
|
|
|
|
|
2021-10-08 15:17:17 +00:00
|
|
|
nix_2_4 = callPackage common (rec {
|
|
|
|
pname = "nix";
|
2021-12-06 16:07:01 +00:00
|
|
|
version = "2.4";
|
2021-10-08 15:17:17 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "NixOS";
|
|
|
|
repo = "nix";
|
|
|
|
rev = version;
|
2021-12-06 16:07:01 +00:00
|
|
|
sha256 = "sha256-op48CCDgLHK0qV1Batz4Ln5FqBiRjlE6qHTiZgt3b6k=";
|
2021-10-08 15:17:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
boehmgc = boehmgc_nixUnstable;
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
patches = [ installNlohmannJsonPatch ];
|
|
|
|
|
2021-10-08 15:17:17 +00:00
|
|
|
inherit storeDir stateDir confDir;
|
|
|
|
});
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
nixUnstable = lib.lowPrio (callPackage common rec {
|
2021-04-13 19:44:15 +00:00
|
|
|
pname = "nix";
|
2021-10-08 15:17:17 +00:00
|
|
|
version = "2.5${suffix}";
|
2021-12-19 01:06:50 +00:00
|
|
|
suffix = "pre20211206_${lib.substring 0 7 src.rev}";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "NixOS";
|
|
|
|
repo = "nix";
|
2021-12-19 01:06:50 +00:00
|
|
|
rev = "d1aaa7ef71713b6693ad3ddf8704ce62bab82095";
|
|
|
|
sha256 = "sha256-zdMODMLdJ0smEEzNMOoIzBxt9QWVzgMvr+pwxkhtD4g=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-07-21 07:28:18 +00:00
|
|
|
boehmgc = boehmgc_nixUnstable;
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
patches = [ installNlohmannJsonPatch ];
|
|
|
|
|
2021-07-21 07:28:18 +00:00
|
|
|
inherit storeDir stateDir confDir;
|
2021-05-20 23:08:51 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|