|
| 1 | +{ |
| 2 | + lib, |
| 3 | + fetchFromGitHub, |
| 4 | + version, |
| 5 | + suffix ? "", |
| 6 | + hash ? null, |
| 7 | + src ? fetchFromGitHub { |
| 8 | + owner = "NixOS"; |
| 9 | + repo = "nix"; |
| 10 | + rev = version; |
| 11 | + inherit hash; |
| 12 | + }, |
| 13 | + patches ? [ ], |
| 14 | + maintainers ? lib.teams.nix.members ++ [ |
| 15 | + lib.maintainers.lovesegfault |
| 16 | + lib.maintainers.artturin |
| 17 | + ], |
| 18 | + self_attribute_name, |
| 19 | +}@args: |
| 20 | +assert (hash == null) -> (src != null); |
| 21 | +{ |
| 22 | + stdenv, |
| 23 | + bison, |
| 24 | + boehmgc, |
| 25 | + boost, |
| 26 | + brotli, |
| 27 | + busybox-sandbox-shell, |
| 28 | + bzip2, |
| 29 | + callPackage, |
| 30 | + cmake, |
| 31 | + curl, |
| 32 | + darwin, |
| 33 | + doxygen, |
| 34 | + editline, |
| 35 | + flex, |
| 36 | + git, |
| 37 | + gtest, |
| 38 | + jq, |
| 39 | + lib, |
| 40 | + libarchive, |
| 41 | + libblake3, |
| 42 | + libcpuid, |
| 43 | + libgit2, |
| 44 | + libsodium, |
| 45 | + lowdown, |
| 46 | + lowdown-unsandboxed, |
| 47 | + toml11, |
| 48 | + man, |
| 49 | + meson, |
| 50 | + ninja, |
| 51 | + mdbook, |
| 52 | + mdbook-linkcheck, |
| 53 | + nlohmann_json, |
| 54 | + nixosTests, |
| 55 | + openssl, |
| 56 | + perl, |
| 57 | + python3, |
| 58 | + pkg-config, |
| 59 | + rapidcheck, |
| 60 | + rsync, |
| 61 | + Security, |
| 62 | + sqlite, |
| 63 | + util-linuxMinimal, |
| 64 | + xz, |
| 65 | + enableDocumentation ? stdenv.buildPlatform.canExecute stdenv.hostPlatform, |
| 66 | + enableStatic ? stdenv.hostPlatform.isStatic, |
| 67 | + withAWS ? !enableStatic && (stdenv.hostPlatform.isLinux || stdenv.hostPlatform.isDarwin), |
| 68 | + aws-sdk-cpp, |
| 69 | + withLibseccomp ? lib.meta.availableOn stdenv.hostPlatform libseccomp, |
| 70 | + libseccomp, |
| 71 | + |
| 72 | + confDir, |
| 73 | + stateDir, |
| 74 | + storeDir, |
| 75 | + |
| 76 | + # passthru tests |
| 77 | + pkgsi686Linux, |
| 78 | + pkgsStatic, |
| 79 | + runCommand, |
| 80 | + pkgs, |
| 81 | +}: |
| 82 | + |
| 83 | +stdenv.mkDerivation (finalAttrs: { |
| 84 | + pname = "nix"; |
| 85 | + |
| 86 | + version = "${version}${suffix}"; |
| 87 | + VERSION_SUFFIX = suffix; |
| 88 | + |
| 89 | + inherit src patches; |
| 90 | + |
| 91 | + outputs = |
| 92 | + [ |
| 93 | + "out" |
| 94 | + "dev" |
| 95 | + ] |
| 96 | + ++ lib.optionals enableDocumentation [ |
| 97 | + "man" |
| 98 | + "doc" |
| 99 | + ]; |
| 100 | + |
| 101 | + hardeningEnable = lib.optionals (!stdenv.hostPlatform.isDarwin) [ "pie" ]; |
| 102 | + |
| 103 | + hardeningDisable = [ |
| 104 | + "shadowstack" |
| 105 | + ] ++ lib.optional stdenv.hostPlatform.isMusl "fortify"; |
| 106 | + |
| 107 | + nativeCheckInputs = [ |
| 108 | + git |
| 109 | + man |
| 110 | + ]; |
| 111 | + |
| 112 | + nativeBuildInputs = |
| 113 | + [ |
| 114 | + bison |
| 115 | + cmake |
| 116 | + flex |
| 117 | + jq |
| 118 | + meson |
| 119 | + ninja |
| 120 | + pkg-config |
| 121 | + rsync |
| 122 | + ] |
| 123 | + ++ lib.optionals enableDocumentation [ |
| 124 | + (lib.getBin lowdown-unsandboxed) |
| 125 | + mdbook |
| 126 | + mdbook-linkcheck |
| 127 | + ] |
| 128 | + ++ lib.optionals stdenv.hostPlatform.isLinux [ |
| 129 | + util-linuxMinimal |
| 130 | + ] |
| 131 | + ++ lib.optionals enableDocumentation [ |
| 132 | + python3 |
| 133 | + doxygen |
| 134 | + ]; |
| 135 | + |
| 136 | + buildInputs = |
| 137 | + [ |
| 138 | + boost |
| 139 | + brotli |
| 140 | + bzip2 |
| 141 | + curl |
| 142 | + editline |
| 143 | + libgit2 |
| 144 | + libsodium |
| 145 | + lowdown |
| 146 | + openssl |
| 147 | + sqlite |
| 148 | + toml11 |
| 149 | + xz |
| 150 | + ] |
| 151 | + ++ lib.optionals (lib.versionAtLeast version "2.26") [ |
| 152 | + libblake3 |
| 153 | + ] |
| 154 | + ++ lib.optionals stdenv.hostPlatform.isDarwin [ |
| 155 | + Security |
| 156 | + ] |
| 157 | + ++ lib.optionals stdenv.hostPlatform.isx86_64 [ |
| 158 | + libcpuid |
| 159 | + ] |
| 160 | + ++ lib.optionals withLibseccomp [ |
| 161 | + libseccomp |
| 162 | + ] |
| 163 | + ++ lib.optionals withAWS [ |
| 164 | + aws-sdk-cpp |
| 165 | + ] |
| 166 | + ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ |
| 167 | + darwin.apple_sdk.libs.sandbox |
| 168 | + ]; |
| 169 | + |
| 170 | + propagatedBuildInputs = [ |
| 171 | + boehmgc |
| 172 | + nlohmann_json |
| 173 | + libarchive |
| 174 | + ]; |
| 175 | + |
| 176 | + checkInputs = [ |
| 177 | + gtest |
| 178 | + rapidcheck |
| 179 | + ]; |
| 180 | + |
| 181 | + postPatch = '' |
| 182 | + patchShebangs --build tests |
| 183 | + ''; |
| 184 | + |
| 185 | + preConfigure = |
| 186 | + # Copy libboost_context so we don't get all of Boost in our closure. |
| 187 | + # https://github.com/NixOS/nixpkgs/issues/45462 |
| 188 | + lib.optionalString (!enableStatic) '' |
| 189 | + mkdir -p $out/lib |
| 190 | + cp -pd ${boost}/lib/{libboost_context*,libboost_thread*,libboost_system*} $out/lib |
| 191 | + rm -f $out/lib/*.a |
| 192 | + ${lib.optionalString stdenv.hostPlatform.isLinux '' |
| 193 | + chmod u+w $out/lib/*.so.* |
| 194 | + patchelf --set-rpath $out/lib:${lib.getLib stdenv.cc.cc}/lib $out/lib/libboost_thread.so.* |
| 195 | + ''} |
| 196 | + ''; |
| 197 | + |
| 198 | + dontUseCmakeConfigure = true; |
| 199 | + |
| 200 | + mesonFlags = |
| 201 | + [ |
| 202 | + (lib.mesonBool "bindings" false) |
| 203 | + (lib.mesonOption "libstore:store-dir" storeDir) |
| 204 | + (lib.mesonOption "libstore:localstatedir" stateDir) |
| 205 | + (lib.mesonOption "libstore:sysconfdir" confDir) |
| 206 | + (lib.mesonEnable "libutil:cpuid" stdenv.hostPlatform.isx86_64) |
| 207 | + (lib.mesonEnable "libstore:seccomp-sandboxing" withLibseccomp) |
| 208 | + (lib.mesonBool "libstore:embedded-sandbox-shell" ( |
| 209 | + stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isStatic |
| 210 | + )) |
| 211 | + (lib.mesonBool "doc-gen" enableDocumentation) |
| 212 | + ] |
| 213 | + ++ lib.optionals stdenv.hostPlatform.isLinux [ |
| 214 | + (lib.mesonOption "libstore:sandbox-shell" "${busybox-sandbox-shell}/bin/busybox") |
| 215 | + # RISC-V support in progress https://github.com/seccomp/libseccomp/pull/50 |
| 216 | + ] |
| 217 | + ++ lib.optionals (stdenv.cc.isGNU && !enableStatic) [ |
| 218 | + # TODO: do we still need this? |
| 219 | + # "--enable-lto" |
| 220 | + ]; |
| 221 | + |
| 222 | + doCheck = true; |
| 223 | + |
| 224 | + # socket path becomes too long otherwise |
| 225 | + preInstallCheck = |
| 226 | + lib.optionalString stdenv.hostPlatform.isDarwin '' |
| 227 | + export TMPDIR=$NIX_BUILD_TOP |
| 228 | + '' |
| 229 | + # See https://github.com/NixOS/nix/issues/5687 |
| 230 | + + lib.optionalString (stdenv.hostPlatform.system == "aarch64-linux") '' |
| 231 | + echo "exit 0" > tests/functional/flakes/show.sh |
| 232 | + '' |
| 233 | + + '' |
| 234 | + # nixStatic otherwise does not find its man pages in tests. |
| 235 | + export MANPATH=$man/share/man:$MANPATH |
| 236 | + ''; |
| 237 | + |
| 238 | + separateDebugInfo = stdenv.hostPlatform.isLinux && enableStatic; |
| 239 | + |
| 240 | + passthru = { |
| 241 | + inherit aws-sdk-cpp boehmgc; |
| 242 | + |
| 243 | + # TODO: |
| 244 | + perl-bindings = perl.pkgs.toPerlModule ( |
| 245 | + callPackage ./nix-perl.nix { |
| 246 | + nix = finalAttrs.finalPackage; |
| 247 | + inherit Security; |
| 248 | + } |
| 249 | + ); |
| 250 | + |
| 251 | + tests = import ./tests.nix { |
| 252 | + inherit |
| 253 | + runCommand |
| 254 | + version |
| 255 | + src |
| 256 | + lib |
| 257 | + stdenv |
| 258 | + pkgs |
| 259 | + pkgsi686Linux |
| 260 | + pkgsStatic |
| 261 | + nixosTests |
| 262 | + self_attribute_name |
| 263 | + ; |
| 264 | + nix = finalAttrs.finalPackage; |
| 265 | + }; |
| 266 | + }; |
| 267 | + |
| 268 | + # point 'nix edit' and ofborg at the file that defines the attribute, |
| 269 | + # not this common file. |
| 270 | + pos = builtins.unsafeGetAttrPos "version" args; |
| 271 | + meta = with lib; { |
| 272 | + description = "Powerful package manager that makes package management reliable and reproducible"; |
| 273 | + longDescription = '' |
| 274 | + Nix is a powerful package manager for Linux and other Unix systems that |
| 275 | + makes package management reliable and reproducible. It provides atomic |
| 276 | + upgrades and rollbacks, side-by-side installation of multiple versions of |
| 277 | + a package, multi-user package management and easy setup of build |
| 278 | + environments. |
| 279 | + ''; |
| 280 | + homepage = "https://nixos.org/"; |
| 281 | + license = licenses.lgpl21Plus; |
| 282 | + inherit maintainers; |
| 283 | + platforms = platforms.unix; |
| 284 | + outputsToInstall = [ "out" ] ++ optional enableDocumentation "man"; |
| 285 | + mainProgram = "nix"; |
| 286 | + }; |
| 287 | +}) |
0 commit comments