diff options
-rw-r--r-- | package.nix | 99 |
1 files changed, 55 insertions, 44 deletions
diff --git a/package.nix b/package.nix index 05503ae98..cc5902a91 100644 --- a/package.nix +++ b/package.nix @@ -85,6 +85,7 @@ let inherit (__forDefaults) canRunInstalled; inherit (lib) fileset; + inherit (stdenv) hostPlatform buildPlatform; version = lib.fileContents ./.version + versionSuffix; @@ -187,23 +188,23 @@ stdenv.mkDerivation (finalAttrs: { dontBuild = false; mesonFlags = - lib.optionals stdenv.hostPlatform.isLinux [ + lib.optionals hostPlatform.isLinux [ # You'd think meson could just find this in PATH, but busybox is in buildInputs, # which don't actually get added to PATH. And buildInputs is correct over # nativeBuildInputs since this should be a busybox executable on the host. "-Dsandbox-shell=${lib.getExe' busybox-sandbox-shell "busybox"}" ] - ++ lib.optional stdenv.hostPlatform.isStatic "-Denable-embedded-sandbox-shell=true" + ++ lib.optional hostPlatform.isStatic "-Denable-embedded-sandbox-shell=true" ++ lib.optional (finalAttrs.dontBuild) "-Denable-build=false" ++ [ # mesonConfigurePhase automatically passes -Dauto_features=enabled, # so we must explicitly enable or disable features that we are not passing # dependencies for. (lib.mesonEnable "internal-api-docs" internalApiDocs) - (lib.mesonBool "enable-tests" finalAttrs.doCheck) + (lib.mesonBool "enable-tests" finalAttrs.finalPackage.doCheck) (lib.mesonBool "enable-docs" canRunInstalled) ] - ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) "--cross-file=${mesonCrossFile}"; + ++ lib.optional (hostPlatform != buildPlatform) "--cross-file=${mesonCrossFile}"; # We only include CMake so that Meson can locate toml11, which only ships CMake dependency metadata. dontUseCmakeConfigure = true; @@ -231,7 +232,7 @@ stdenv.mkDerivation (finalAttrs: { jq lsof ] - ++ lib.optional stdenv.hostPlatform.isLinux util-linuxMinimal + ++ lib.optional hostPlatform.isLinux util-linuxMinimal ++ lib.optional (!officialRelease && buildUnreleasedNotes) build-release-notes ++ lib.optional internalApiDocs doxygen; @@ -251,14 +252,14 @@ stdenv.mkDerivation (finalAttrs: { toml11 lix-doc ] - ++ lib.optionals stdenv.hostPlatform.isLinux [ + ++ lib.optionals hostPlatform.isLinux [ libseccomp busybox-sandbox-shell ] ++ lib.optional internalApiDocs rapidcheck - ++ lib.optional stdenv.hostPlatform.isx86_64 libcpuid + ++ lib.optional hostPlatform.isx86_64 libcpuid # There have been issues building these dependencies - ++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) aws-sdk-cpp-nix + ++ lib.optional (hostPlatform == buildPlatform) aws-sdk-cpp-nix ++ lib.optionals (finalAttrs.dontBuild) maybePropagatedInputs; checkInputs = [ @@ -278,18 +279,18 @@ stdenv.mkDerivation (finalAttrs: { }; preConfigure = - lib.optionalString (!finalAttrs.dontBuild && !stdenv.hostPlatform.isStatic) '' + lib.optionalString (!finalAttrs.dontBuild && !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*} $out/lib rm -f $out/lib/*.a '' - + lib.optionalString (!finalAttrs.dontBuild && stdenv.hostPlatform.isLinux) '' + + lib.optionalString (!finalAttrs.dontBuild && hostPlatform.isLinux && !hostPlatform.isStatic) '' chmod u+w $out/lib/*.so.* patchelf --set-rpath $out/lib:${stdenv.cc.cc.lib}/lib $out/lib/libboost_thread.so.* '' - + lib.optionalString (!finalAttrs.dontBuild && stdenv.hostPlatform.isDarwin) '' + + lib.optionalString (!finalAttrs.dontBuild && hostPlatform.isDarwin) '' for LIB in $out/lib/*.dylib; do chmod u+w $LIB install_name_tool -id $LIB $LIB @@ -333,7 +334,7 @@ stdenv.mkDerivation (finalAttrs: { mkdir -p $doc/nix-support echo "doc manual $doc/share/doc/nix/manual" >> $doc/nix-support/hydra-build-products '' - + lib.optionalString stdenv.hostPlatform.isStatic '' + + lib.optionalString hostPlatform.isStatic '' mkdir -p $out/nix-support echo "file binary-dist $out/bin/nix" >> $out/nix-support/hydra-build-products '' @@ -364,12 +365,12 @@ stdenv.mkDerivation (finalAttrs: { runHook postInstallCheck ''; - separateDebugInfo = !stdenv.hostPlatform.isStatic && !finalAttrs.dontBuild; + separateDebugInfo = !hostPlatform.isStatic && !finalAttrs.dontBuild; strictDeps = true; # strictoverflow is disabled because we trap on signed overflow instead - hardeningDisable = [ "strictoverflow" ] ++ lib.optional stdenv.hostPlatform.isStatic "pie"; + hardeningDisable = [ "strictoverflow" ] ++ lib.optional hostPlatform.isStatic "pie"; meta = { mainProgram = "nix"; @@ -398,7 +399,7 @@ stdenv.mkDerivation (finalAttrs: { contribNotice, }: let - glibcFix = lib.optionalAttrs (stdenv.buildPlatform.isLinux && glibcLocales != null) { + glibcFix = lib.optionalAttrs (buildPlatform.isLinux && glibcLocales != null) { # Required to make non-NixOS Linux not complain about missing locale files during configure in a dev shell LOCALE_ARCHIVE = "${lib.getLib pkgs.glibcLocales}/lib/locale/locale-archive"; }; @@ -416,13 +417,19 @@ stdenv.mkDerivation (finalAttrs: { name = "lix-shell-env"; - inputsFrom = [ finalAttrs ]; + # finalPackage is necessary to propagate stuff that is set by mkDerivation itself, + # like doCheck. + inputsFrom = [ finalAttrs.finalPackage ]; # For Meson to find Boost. env = finalAttrs.env; + # I guess this is necessary because mesonFlags to mkDerivation doesn't propagate in inputsFrom, + # which only propagates stuff set in hooks? idk. + inherit (finalAttrs) mesonFlags; + packages = - lib.optional (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) clang-tools_llvm + lib.optional (stdenv.cc.isClang && hostPlatform == buildPlatform) clang-tools_llvm ++ [ just nixfmt @@ -435,37 +442,41 @@ stdenv.mkDerivation (finalAttrs: { llvmPackages.clang-unwrapped.dev ] ++ lib.optional (pre-commit-checks ? enabledPackages) pre-commit-checks.enabledPackages - ++ lib.optional (lib.meta.availableOn stdenv.buildPlatform clangbuildanalyzer) clangbuildanalyzer + ++ lib.optional (lib.meta.availableOn buildPlatform clangbuildanalyzer) clangbuildanalyzer ++ finalAttrs.checkInputs; shellHook = '' # don't re-run the hook in (other) nested nix-shells - if [[ $name != lix-shell-env ]]; then - return; - fi - - PATH=$prefix/bin:$PATH - unset PYTHONPATH - export MANPATH=$out/share/man:$MANPATH - - # Make bash completion work. - XDG_DATA_DIRS+=:$out/share - - ${lib.optionalString (pre-commit-checks ? shellHook) pre-commit-checks.shellHook} - # Allow `touch .nocontribmsg` to turn this notice off. - if ! [[ -f .nocontribmsg ]]; then - cat ${contribNotice} - fi - - # Install the Gerrit commit-msg hook. - # (git common dir is the main .git, including for worktrees) - if gitcommondir=$(git rev-parse --git-common-dir 2>/dev/null) && [[ ! -f "$gitcommondir/hooks/commit-msg" ]]; then - echo 'Installing Gerrit commit-msg hook (adds Change-Id to commit messages)' >&2 - mkdir -p "$gitcommondir/hooks" - curl -s -Lo "$gitcommondir/hooks/commit-msg" https://gerrit.lix.systems/tools/hooks/commit-msg - chmod u+x "$gitcommondir/hooks/commit-msg" - fi - unset gitcommondir + function lixShellHook() { + if [[ $name != lix-shell-env ]]; then + return; + fi + + PATH=$prefix/bin:$PATH + unset PYTHONPATH + export MANPATH=$out/share/man:$MANPATH + + # Make bash completion work. + XDG_DATA_DIRS+=:$out/share + + ${lib.optionalString (pre-commit-checks ? shellHook) pre-commit-checks.shellHook} + # Allow `touch .nocontribmsg` to turn this notice off. + if ! [[ -f .nocontribmsg ]]; then + cat ${contribNotice} + fi + + # Install the Gerrit commit-msg hook. + # (git common dir is the main .git, including for worktrees) + if gitcommondir=$(git rev-parse --git-common-dir 2>/dev/null) && [[ ! -f "$gitcommondir/hooks/commit-msg" ]]; then + echo 'Installing Gerrit commit-msg hook (adds Change-Id to commit messages)' >&2 + mkdir -p "$gitcommondir/hooks" + curl -s -Lo "$gitcommondir/hooks/commit-msg" https://gerrit.lix.systems/tools/hooks/commit-msg + chmod u+x "$gitcommondir/hooks/commit-msg" + fi + unset gitcommondir + } + + lixShellHook ''; } ); |