diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2024-07-09 18:18:47 -0400 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2024-07-09 18:18:47 -0400 |
commit | 000b58721fef0d1cf693a6f2f4fa442b66fbe2bb (patch) | |
tree | c336d2806dd00527b1270c7e0d94d3209c1b98cf /pkgs/build-support | |
parent | 676df1cf2d5b59632a9f7e36d655e10f6c6d2063 (diff) | |
parent | 2ae9aee12915b32a904a0f8dda95928cd86b27c4 (diff) |
Merge remote-tracking branch 'upstream/master' into openbsd-static
Diffstat (limited to 'pkgs/build-support')
40 files changed, 256 insertions, 908 deletions
diff --git a/pkgs/build-support/appimage/default.nix b/pkgs/build-support/appimage/default.nix index 0d44a5ab23e96..6451feeabe3c9 100644 --- a/pkgs/build-support/appimage/default.nix +++ b/pkgs/build-support/appimage/default.nix @@ -74,7 +74,7 @@ rec { targetPkgs = pkgs: with pkgs; [ gtk3 bashInteractive - gnome.zenity + zenity xorg.xrandr which perl @@ -162,7 +162,7 @@ rec { vulkan-loader flac - freeglut + libglut libjpeg libpng12 libpulseaudio diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 952bd85d4b011..b7561f1aab55e 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -45,6 +45,7 @@ "relro" "stackprotector" "strictoverflow" + "zerocallusedregs" ] ++ lib.optional (with stdenvNoCC; lib.any (x: x) [ # OpenBSD static linking requires PIE (with targetPlatform; isOpenBSD && isStatic) diff --git a/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh b/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh index a1d06b9c6b0ae..51bfeb18f58a1 100644 --- a/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh +++ b/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh @@ -7,5 +7,5 @@ for p in "${params[@]}"; do done if $needsTarget; then - extraBefore+=(-target @defaultTarget@ @march@) + extraBefore+=(-target @defaultTarget@ @machineFlags@) fi diff --git a/pkgs/build-support/cc-wrapper/add-hardening.sh b/pkgs/build-support/cc-wrapper/add-hardening.sh index ef166e2f50c5e..0dca3b3347e5b 100644 --- a/pkgs/build-support/cc-wrapper/add-hardening.sh +++ b/pkgs/build-support/cc-wrapper/add-hardening.sh @@ -32,7 +32,7 @@ if [[ -n "${hardeningEnableMap[fortify3]-}" ]]; then fi if (( "${NIX_DEBUG:-0}" >= 1 )); then - declare -a allHardeningFlags=(fortify fortify3 stackprotector pie pic strictoverflow format trivialautovarinit zerocallusedregs) + declare -a allHardeningFlags=(fortify fortify3 stackprotector stackclashprotection pie pic strictoverflow format trivialautovarinit zerocallusedregs) declare -A hardeningDisableMap=() # Determine which flags were effectively disabled so we can report below. @@ -79,6 +79,10 @@ for flag in "${!hardeningEnableMap[@]}"; do if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling stackprotector >&2; fi hardeningCFlagsBefore+=('-fstack-protector-strong' '--param' 'ssp-buffer-size=4') ;; + stackclashprotection) + if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling stack-clash-protection >&2; fi + hardeningCFlagsBefore+=('-fstack-clash-protection') + ;; pie) # NB: we do not use `+=` here, because PIE flags must occur before any PIC flags if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling CFlags -fPIE >&2; fi diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 4adc1dcb1f8d8..d842f3fc70909 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -67,6 +67,7 @@ let concatMapStrings concatStringsSep escapeShellArg + escapeShellArgs getBin getDev getLib @@ -234,6 +235,32 @@ let then guess else null; + thumb = if targetPlatform.gcc.thumb then "thumb" else "arm"; + tune = if targetPlatform ? gcc.tune + then findBestTuneApproximation targetPlatform.gcc.tune + else null; + + # Machine flags. These are necessary to support + + # TODO: We should make a way to support miscellaneous machine + # flags and other gcc flags as well. + + machineFlags = + # Always add -march based on cpu in triple. Sometimes there is a + # discrepency (x86_64 vs. x86-64), so we provide an "arch" arg in + # that case. + optional (targetPlatform ? gcc.arch && !(targetPlatform.isDarwin && targetPlatform.isAarch64) && isGccArchSupported targetPlatform.gcc.arch) "-march=${targetPlatform.gcc.arch}" ++ + # TODO: aarch64-darwin has mcpu incompatible with gcc + optional (targetPlatform ? gcc.cpu && !(targetPlatform.isDarwin && targetPlatform.isAarch64)) "-mcpu=${targetPlatform.gcc.cpu}" ++ + # -mfloat-abi only matters on arm32 but we set it here + # unconditionally just in case. If the abi specifically sets hard + # vs. soft floats we use it here. + optional (targetPlatform ? gcc.float-abi) "-mfloat-abi=${targetPlatform.gcc.float-abi}" ++ + optional (targetPlatform ? gcc.fpu) "-mfpu=${targetPlatform.gcc.fpu}" ++ + optional (targetPlatform ? gcc.mode) "-mmode=${targetPlatform.gcc.mode}" ++ + optional (targetPlatform ? gcc.thumb) "-m${thumb}" ++ + optional (tune != null) "-mtune=${tune}"; + defaultHardeningFlags = bintools.defaultHardeningFlags or []; # if cc.hardeningUnsupportedFlagsByTargetPlatform exists, this is @@ -610,53 +637,11 @@ stdenvNoCC.mkDerivation { export hardening_unsupported_flags="${concatStringsSep " " ccHardeningUnsupportedFlags}" '' - # Machine flags. These are necessary to support - - # TODO: We should make a way to support miscellaneous machine - # flags and other gcc flags as well. - - # Always add -march based on cpu in triple. Sometimes there is a - # discrepency (x86_64 vs. x86-64), so we provide an "arch" arg in - # that case. - # # For clang, this is handled in add-clang-cc-cflags-before.sh - - # TODO: aarch64-darwin has mcpu incompatible with gcc - + optionalString ((targetPlatform ? gcc.arch) && !isClang && !(targetPlatform.isDarwin && targetPlatform.isAarch64) && - isGccArchSupported targetPlatform.gcc.arch) '' - echo "-march=${targetPlatform.gcc.arch}" >> $out/nix-support/cc-cflags-before - '' - - # -mcpu is not very useful, except on PowerPC where it is used - # instead of march. On all other platforms you should use mtune - # and march instead. - # TODO: aarch64-darwin has mcpu incompatible with gcc - + optionalString ((targetPlatform ? gcc.cpu) && (isClang || !(targetPlatform.isDarwin && targetPlatform.isAarch64))) '' - echo "-mcpu=${targetPlatform.gcc.cpu}" >> $out/nix-support/cc-cflags-before + + lib.optionalString (!isClang && machineFlags != []) '' + printf "%s\n" ${lib.escapeShellArgs machineFlags} >> $out/nix-support/cc-cflags-before '' - # -mfloat-abi only matters on arm32 but we set it here - # unconditionally just in case. If the abi specifically sets hard - # vs. soft floats we use it here. - + optionalString (targetPlatform ? gcc.float-abi) '' - echo "-mfloat-abi=${targetPlatform.gcc.float-abi}" >> $out/nix-support/cc-cflags-before - '' - + optionalString (targetPlatform ? gcc.fpu) '' - echo "-mfpu=${targetPlatform.gcc.fpu}" >> $out/nix-support/cc-cflags-before - '' - + optionalString (targetPlatform ? gcc.mode) '' - echo "-mmode=${targetPlatform.gcc.mode}" >> $out/nix-support/cc-cflags-before - '' - + optionalString (targetPlatform ? gcc.thumb) '' - echo "-m${if targetPlatform.gcc.thumb then "thumb" else "arm"}" >> $out/nix-support/cc-cflags-before - '' - + (let tune = if targetPlatform ? gcc.tune - then findBestTuneApproximation targetPlatform.gcc.tune - else null; - in optionalString (tune != null) '' - echo "-mtune=${tune}" >> $out/nix-support/cc-cflags-before - '') - # TODO: categorize these and figure out a better place for them + optionalString targetPlatform.isWindows '' hardening_unsupported_flags+=" pic" @@ -718,9 +703,7 @@ stdenvNoCC.mkDerivation { ## + optionalString isClang '' # Escape twice: once for this script, once for the one it gets substituted into. - export march=${escapeShellArg - (optionalString (targetPlatform ? gcc.arch) - (escapeShellArg "-march=${targetPlatform.gcc.arch}"))} + export machineFlags=${escapeShellArg (escapeShellArgs machineFlags)} export defaultTarget=${targetPlatform.config} substituteAll ${./add-clang-cc-cflags-before.sh} $out/nix-support/add-local-cc-cflags-before.sh '' diff --git a/pkgs/build-support/dev-shell-tools/README.md b/pkgs/build-support/dev-shell-tools/README.md new file mode 100644 index 0000000000000..d6d9a8c8ad0df --- /dev/null +++ b/pkgs/build-support/dev-shell-tools/README.md @@ -0,0 +1,13 @@ + +# `devShellTools` + +This directory implements the `pkgs.devShellTools` library. + +# Contributing to `devShellTools` + +- Documentation should be contributed to the Nixpkgs manual, not here. + +- Tests are available in the `tests` directory. + You may run them with `nix-build -A tests.devShellTools`. + +- See [../../README.md](../../README.md) for more information on contributing to Nixpkgs. diff --git a/pkgs/build-support/dev-shell-tools/default.nix b/pkgs/build-support/dev-shell-tools/default.nix new file mode 100644 index 0000000000000..cd5fa5f5937ef --- /dev/null +++ b/pkgs/build-support/dev-shell-tools/default.nix @@ -0,0 +1,16 @@ +{ lib }: +let + inherit (builtins) typeOf; +in +rec { + # This function closely mirrors what this Nix code does: + # https://github.com/NixOS/nix/blob/2.8.0/src/libexpr/primops.cc#L1102 + # https://github.com/NixOS/nix/blob/2.8.0/src/libexpr/eval.cc#L1981-L2036 + valueToString = value: + # We can't just use `toString` on all derivation attributes because that + # would not put path literals in the closure. So we explicitly copy + # those into the store here + if typeOf value == "path" then "${value}" + else if typeOf value == "list" then toString (map valueToString value) + else toString value; +} diff --git a/pkgs/build-support/dev-shell-tools/tests/default.nix b/pkgs/build-support/dev-shell-tools/tests/default.nix new file mode 100644 index 0000000000000..bfedc04409a98 --- /dev/null +++ b/pkgs/build-support/dev-shell-tools/tests/default.nix @@ -0,0 +1,45 @@ +{ + devShellTools, + emptyFile, + lib, + stdenv, + hello, +}: +let + inherit (lib) escapeShellArg; +in +{ + # nix-build -A tests.devShellTools.valueToString + valueToString = + let inherit (devShellTools) valueToString; in + + stdenv.mkDerivation { + name = "devShellTools-valueToString-built-tests"; + + # Test inputs + inherit emptyFile hello; + one = 1; + boolTrue = true; + boolFalse = false; + foo = "foo"; + list = [ 1 2 3 ]; + pathDefaultNix = ./default.nix; + packages = [ hello emptyFile ]; + # TODO: nested lists + + buildCommand = '' + touch $out + ( set -x + [[ "$one" = ${escapeShellArg (valueToString 1)} ]] + [[ "$boolTrue" = ${escapeShellArg (valueToString true)} ]] + [[ "$boolFalse" = ${escapeShellArg (valueToString false)} ]] + [[ "$foo" = ${escapeShellArg (valueToString "foo")} ]] + [[ "$hello" = ${escapeShellArg (valueToString hello)} ]] + [[ "$list" = ${escapeShellArg (valueToString [ 1 2 3 ])} ]] + [[ "$packages" = ${escapeShellArg (valueToString [ hello emptyFile ])} ]] + [[ "$pathDefaultNix" = ${escapeShellArg (valueToString ./default.nix)} ]] + [[ "$emptyFile" = ${escapeShellArg (valueToString emptyFile)} ]] + ) >log 2>&1 || { cat log; exit 1; } + ''; + }; +} diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix index 1d1989d27fbb2..ea461ccffa078 100644 --- a/pkgs/build-support/docker/default.nix +++ b/pkgs/build-support/docker/default.nix @@ -4,6 +4,7 @@ , callPackage , closureInfo , coreutils +, devShellTools , e2fsprogs , proot , fakeNss @@ -49,6 +50,10 @@ let toList ; + inherit (devShellTools) + valueToString + ; + mkDbExtraCommand = contents: let contentsList = if builtins.isList contents then contents else [ contents ]; @@ -1141,7 +1146,7 @@ rec { # A binary that calls the command to build the derivation builder = writeShellScriptBin "buildDerivation" '' - exec ${lib.escapeShellArg (stringValue drv.drvAttrs.builder)} ${lib.escapeShellArgs (map stringValue drv.drvAttrs.args)} + exec ${lib.escapeShellArg (valueToString drv.drvAttrs.builder)} ${lib.escapeShellArgs (map valueToString drv.drvAttrs.args)} ''; staticPath = "${dirOf shell}:${lib.makeBinPath [ builder ]}"; @@ -1173,20 +1178,9 @@ rec { # https://github.com/NixOS/nix/blob/2.8.0/src/libstore/globals.hh#L464-L465 sandboxBuildDir = "/build"; - # This function closely mirrors what this Nix code does: - # https://github.com/NixOS/nix/blob/2.8.0/src/libexpr/primops.cc#L1102 - # https://github.com/NixOS/nix/blob/2.8.0/src/libexpr/eval.cc#L1981-L2036 - stringValue = value: - # We can't just use `toString` on all derivation attributes because that - # would not put path literals in the closure. So we explicitly copy - # those into the store here - if builtins.typeOf value == "path" then "${value}" - else if builtins.typeOf value == "list" then toString (map stringValue value) - else toString value; - # https://github.com/NixOS/nix/blob/2.8.0/src/libstore/build/local-derivation-goal.cc#L992-L1004 drvEnv = lib.mapAttrs' (name: value: - let str = stringValue value; + let str = valueToString value; in if lib.elem name (drv.drvAttrs.passAsFile or []) then lib.nameValuePair "${name}Path" (writeText "pass-as-text-${name}" str) else lib.nameValuePair name str diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix index 52706ef6b21ff..4949d6b8a8888 100644 --- a/pkgs/build-support/docker/examples.nix +++ b/pkgs/build-support/docker/examples.nix @@ -619,10 +619,14 @@ rec { fakeRootCommands = '' mkdir -p ./home/alice chown 1000 ./home/alice - ln -s ${pkgs.hello.overrideAttrs (o: { + ln -s ${pkgs.hello.overrideAttrs (finalAttrs: prevAttrs: { # A unique `hello` to make sure that it isn't included via another mechanism by accident. - configureFlags = o.configureFlags or [] ++ [ " --program-prefix=layeredImageWithFakeRootCommands-" ]; + configureFlags = prevAttrs.configureFlags or [] ++ [ " --program-prefix=layeredImageWithFakeRootCommands-" ]; doCheck = false; + versionCheckProgram = "${builtins.placeholder "out"}/bin/${finalAttrs.meta.mainProgram}"; + meta = prevAttrs.meta // { + mainProgram = "layeredImageWithFakeRootCommands-hello"; + }; })} ./hello ''; }; diff --git a/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix b/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix index 7ae9cfc9f6618..48e6e8ea470a5 100644 --- a/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix @@ -5,6 +5,8 @@ # Name of the nuget package to install, if different from pname , nugetName ? pname # Hash of the nuget package to install, will be given on first build + # nugetHash uses SRI hash and should be preferred +, nugetHash ? "" , nugetSha256 ? "" # Additional nuget deps needed by the tool package , nugetDeps ? (_: []) @@ -24,7 +26,7 @@ buildDotnetModule (args // { nugetDeps = mkNugetDeps { name = pname; nugetDeps = { fetchNuGet }: [ - (fetchNuGet { pname = nugetName; inherit version; sha256 = nugetSha256; }) + (fetchNuGet { pname = nugetName; inherit version; sha256 = nugetSha256; hash = nugetHash; }) ] ++ (nugetDeps fetchNuGet); }; diff --git a/pkgs/build-support/dotnet/fetchnuget/default.nix b/pkgs/build-support/dotnet/fetchnuget/default.nix index 061da746cead0..a8e85270e73fa 100644 --- a/pkgs/build-support/dotnet/fetchnuget/default.nix +++ b/pkgs/build-support/dotnet/fetchnuget/default.nix @@ -5,15 +5,19 @@ attrs @ , version , url ? "https://www.nuget.org/api/v2/package/${pname}/${version}" , sha256 ? "" +, hash ? "" , md5 ? "" , ... }: if md5 != "" then - throw "fetchnuget does not support md5 anymore, please use sha256" + throw "fetchnuget does not support md5 anymore, please use 'hash' attribute with SRI hash" +# This is also detected in fetchurl, but we just throw here to avoid confusion +else if (sha256 != "" && hash != "") then + throw "multiple hashes passed to fetchNuGet" else buildDotnetPackage ({ src = fetchurl { - inherit url sha256; + inherit url sha256 hash; name = "${pname}.${version}.zip"; }; diff --git a/pkgs/build-support/dotnet/make-nuget-deps/default.nix b/pkgs/build-support/dotnet/make-nuget-deps/default.nix index fcd3f9f076b27..cd048bcc30e57 100644 --- a/pkgs/build-support/dotnet/make-nuget-deps/default.nix +++ b/pkgs/build-support/dotnet/make-nuget-deps/default.nix @@ -1,11 +1,14 @@ { linkFarmFromDrvs, fetchurl }: { name, nugetDeps ? import sourceFile, sourceFile ? null }: linkFarmFromDrvs "${name}-nuget-deps" (nugetDeps { - fetchNuGet = { pname, version, sha256 + fetchNuGet = { pname, version, sha256 ? "", hash ? "" , url ? "https://www.nuget.org/api/v2/package/${pname}/${version}" }: fetchurl { name = "${pname}.${version}.nupkg"; - inherit url sha256; + # There is no need to verify whether both sha256 and hash are + # valid here, because nuget-to-nix does not generate a deps.nix + # containing both. + inherit url sha256 hash; }; }) // { inherit sourceFile; diff --git a/pkgs/build-support/dotnet/nuget-to-nix/nuget-to-nix.sh b/pkgs/build-support/dotnet/nuget-to-nix/nuget-to-nix.sh index 2754bfc32d7b7..92b0200ec034d 100755 --- a/pkgs/build-support/dotnet/nuget-to-nix/nuget-to-nix.sh +++ b/pkgs/build-support/dotnet/nuget-to-nix/nuget-to-nix.sh @@ -65,11 +65,12 @@ for package in *; do for source in "${remote_sources[@]}"; do url="${base_addresses[$source]}$package/$version/$package.$version.nupkg" if [[ "$source" == "$used_source" ]]; then - sha256="$(nix-hash --type sha256 --flat --base32 "$version/$package.$version".nupkg)" + hash="$(nix-hash --type sha256 --flat --sri "$version/$package.$version".nupkg)" found=true break else - if sha256=$(nix-prefetch-url "$url" 2>"$tmp"/error); then + if hash=$(nix-prefetch-url "$url" 2>"$tmp"/error); then + hash="$(nix-hash --to-sri --type sha256 "$hash")" # If multiple remote sources are enabled, nuget will try them all # concurrently and use the one that responds first. We always use the # first source that has the package. @@ -91,9 +92,9 @@ for package in *; do fi if [[ "$source" != https://api.nuget.org/v3/index.json ]]; then - echo " (fetchNuGet { pname = \"$id\"; version = \"$version\"; sha256 = \"$sha256\"; url = \"$url\"; })" + echo " (fetchNuGet { pname = \"$id\"; version = \"$version\"; hash = \"$hash\"; url = \"$url\"; })" else - echo " (fetchNuGet { pname = \"$id\"; version = \"$version\"; sha256 = \"$sha256\"; })" + echo " (fetchNuGet { pname = \"$id\"; version = \"$version\"; hash = \"$hash\"; })" fi done cd .. diff --git a/pkgs/build-support/emacs/buffer.nix b/pkgs/build-support/emacs/buffer.nix deleted file mode 100644 index 48a7996916e8d..0000000000000 --- a/pkgs/build-support/emacs/buffer.nix +++ /dev/null @@ -1,77 +0,0 @@ -# Functions to build elisp files to locally configure emcas buffers. -# See https://github.com/shlevy/nix-buffer - -{ lib, writeText, inherit-local }: - -rec { - withPackages = pkgs': let - pkgs = builtins.filter (x: x != null) pkgs'; - extras = map (x: x.emacsBufferSetup pkgs) (builtins.filter (builtins.hasAttr "emacsBufferSetup") pkgs); - in writeText "dir-locals.el" '' - (require 'inherit-local "${inherit-local}/share/emacs/site-lisp/elpa/inherit-local-${inherit-local.version}/inherit-local.elc") - - ; Only set up nixpkgs buffer handling when we have some buffers active - (defvar nixpkgs--buffer-count 0) - (when (eq nixpkgs--buffer-count 0) - (make-variable-buffer-local 'nixpkgs--is-nixpkgs-buffer) - ; When generating a new temporary buffer (one whose name starts with a space), do inherit-local inheritance and make it a nixpkgs buffer - (defun nixpkgs--around-generate (orig name &optional ibh) - (if (and nixpkgs--is-nixpkgs-buffer (eq (aref name 0) ?\s)) - (let ((buf (funcall orig name ibh))) - (progn - (inherit-local-inherit-child buf) - (with-current-buffer buf - (setq nixpkgs--buffer-count (1+ nixpkgs--buffer-count)) - (add-hook 'kill-buffer-hook 'nixpkgs--decrement-buffer-count nil t))) - buf) - (funcall orig name ibh))) - (advice-add 'generate-new-buffer :around #'nixpkgs--around-generate) - ; When we have no more nixpkgs buffers, tear down the buffer handling - (defun nixpkgs--decrement-buffer-count () - (setq nixpkgs--buffer-count (1- nixpkgs--buffer-count)) - (when (eq nixpkgs--buffer-count 0) - (advice-remove 'generate-new-buffer #'nixpkgs--around-generate) - (fmakunbound 'nixpkgs--around-generate) - (fmakunbound 'nixpkgs--decrement-buffer-count)))) - (setq nixpkgs--buffer-count (1+ nixpkgs--buffer-count)) - (add-hook 'kill-buffer-hook 'nixpkgs--decrement-buffer-count nil t) - - ; Add packages to PATH and exec-path - (make-local-variable 'process-environment) - (put 'process-environment 'permanent-local t) - (inherit-local 'process-environment) - ; setenv modifies in place, so copy the environment first - (setq process-environment (copy-tree process-environment)) - (setenv "PATH" (concat "${lib.makeSearchPath "bin" pkgs}:" (getenv "PATH"))) - (inherit-local-permanent exec-path (append '(${builtins.concatStringsSep " " (map (p: "\"${p}/bin\"") pkgs)}) exec-path)) - - (inherit-local-permanent eshell-path-env (concat "${lib.makeSearchPath "bin" pkgs}:" (if (boundp 'eshell-path-env) eshell-path-env (getenv "PATH")))) - - (setq nixpkgs--is-nixpkgs-buffer t) - (inherit-local 'nixpkgs--is-nixpkgs-buffer) - - ${lib.concatStringsSep "\n" extras} - ''; - # nix-buffer function for a project with a bunch of haskell packages - # in one directory - haskellMonoRepo = { project-root # The monorepo root - , haskellPackages # The composed haskell packages set that contains all of the packages - }: { root }: - let # The haskell paths. - haskell-paths = lib.filesystem.haskellPathsInDir project-root; - # Find the haskell package that the 'root' is in, if any. - haskell-path-parent = - let filtered = builtins.filter (name: - lib.hasPrefix (toString (project-root + "/${name}")) (toString root) - ) (builtins.attrNames haskell-paths); - in - if filtered == [] then null else builtins.head filtered; - # We're in the directory of a haskell package - is-haskell-package = haskell-path-parent != null; - haskell-package = haskellPackages.${haskell-path-parent}; - # GHC environment with all needed deps for the haskell package - haskell-package-env = - builtins.head haskell-package.env.nativeBuildInputs; - in - lib.optionalAttrs is-haskell-package (withPackages [ haskell-package-env ]); -} diff --git a/pkgs/build-support/emacs/elpa.nix b/pkgs/build-support/emacs/elpa.nix deleted file mode 100644 index a43578fd3936b..0000000000000 --- a/pkgs/build-support/emacs/elpa.nix +++ /dev/null @@ -1,37 +0,0 @@ -# builder for Emacs packages built for packages.el - -{ lib, stdenv, emacs, texinfo, writeText, gcc }: - -let - handledArgs = [ "files" "fileSpecs" "meta" ]; - genericBuild = import ./generic.nix { inherit lib stdenv emacs texinfo writeText gcc; }; - -in - -{ pname -, version -, src -, meta ? {} -, ... -}@args: - -genericBuild ({ - - dontUnpack = true; - - installPhase = '' - runHook preInstall - - emacs --batch -Q -l ${./elpa2nix.el} \ - -f elpa2nix-install-package \ - "$src" "$out/share/emacs/site-lisp/elpa" - - runHook postInstall - ''; - - meta = { - homepage = args.src.meta.homepage or "https://elpa.gnu.org/packages/${pname}.html"; - } // meta; -} - -// removeAttrs args handledArgs) diff --git a/pkgs/build-support/emacs/elpa2nix.el b/pkgs/build-support/emacs/elpa2nix.el deleted file mode 100644 index 64587c0fad1a7..0000000000000 --- a/pkgs/build-support/emacs/elpa2nix.el +++ /dev/null @@ -1,33 +0,0 @@ -(require 'package) -(package-initialize) - -(defun elpa2nix-install-package () - (if (not noninteractive) - (error "`elpa2nix-install-package' is to be used only with -batch")) - (pcase command-line-args-left - (`(,archive ,elpa) - (progn (setq package-user-dir elpa) - (elpa2nix-install-file archive))))) - -(defun elpa2nix-install-from-buffer () - "Install a package from the current buffer." - (let ((pkg-desc (if (derived-mode-p 'tar-mode) - (package-tar-file-info) - (package-buffer-info)))) - ;; Install the package itself. - (package-unpack pkg-desc) - pkg-desc)) - -(defun elpa2nix-install-file (file) - "Install a package from a file. -The file can either be a tar file or an Emacs Lisp file." - (let ((is-tar (string-match "\\.tar\\'" file))) - (with-temp-buffer - (if is-tar - (insert-file-contents-literally file) - (insert-file-contents file)) - (when is-tar (tar-mode)) - (elpa2nix-install-from-buffer)))) - -;; Allow installing package tarfiles larger than 10MB -(setq large-file-warning-threshold nil) diff --git a/pkgs/build-support/emacs/emacs-funcs.sh b/pkgs/build-support/emacs/emacs-funcs.sh deleted file mode 100644 index e1e6a3b622087..0000000000000 --- a/pkgs/build-support/emacs/emacs-funcs.sh +++ /dev/null @@ -1,34 +0,0 @@ -addToEmacsLoadPath() { - local lispDir="$1" - if [[ -d $lispDir && ${EMACSLOADPATH-} != *"$lispDir":* ]] ; then - # It turns out, that the trailing : is actually required - # see https://www.gnu.org/software/emacs/manual/html_node/elisp/Library-Search.html - export EMACSLOADPATH="$lispDir:${EMACSLOADPATH-}" - fi -} - -addToEmacsNativeLoadPath() { - local nativeDir="$1" - if [[ -d $nativeDir && ${EMACSNATIVELOADPATH-} != *"$nativeDir":* ]]; then - export EMACSNATIVELOADPATH="$nativeDir:${EMACSNATIVELOADPATH-}" - fi -} - -addEmacsVars () { - addToEmacsLoadPath "$1/share/emacs/site-lisp" - - if [ -n "${addEmacsNativeLoadPath:-}" ]; then - addToEmacsNativeLoadPath "$1/share/emacs/native-lisp" - fi - - # Add sub paths to the Emacs load path if it is a directory - # containing .el files. This is necessary to build some packages, - # e.g., using trivialBuild. - for lispDir in \ - "$1/share/emacs/site-lisp/"* \ - "$1/share/emacs/site-lisp/elpa/"*; do - if [[ -d $lispDir && "$(echo "$lispDir"/*.el)" ]] ; then - addToEmacsLoadPath "$lispDir" - fi - done -} diff --git a/pkgs/build-support/emacs/generic.nix b/pkgs/build-support/emacs/generic.nix deleted file mode 100644 index bdf1cd4e50f31..0000000000000 --- a/pkgs/build-support/emacs/generic.nix +++ /dev/null @@ -1,90 +0,0 @@ -# generic builder for Emacs packages - -{ lib, stdenv, emacs, texinfo, writeText, gcc, ... }: - -let - inherit (lib) optionalAttrs getLib; - handledArgs = [ "buildInputs" "packageRequires" "meta" ]; - - setupHook = writeText "setup-hook.sh" '' - source ${./emacs-funcs.sh} - - if [[ ! -v emacsHookDone ]]; then - emacsHookDone=1 - - # If this is for a wrapper derivation, emacs and the dependencies are all - # run-time dependencies. If this is for precompiling packages into bytecode, - # emacs is a compile-time dependency of the package. - addEnvHooks "$hostOffset" addEmacsVars - addEnvHooks "$targetOffset" addEmacsVars - fi - ''; - -in - -{ pname -, version -, buildInputs ? [] -, packageRequires ? [] -, meta ? {} -, ... -}@args: - -stdenv.mkDerivation (finalAttrs: ({ - name = "emacs-${pname}-${finalAttrs.version}"; - - unpackCmd = '' - case "$curSrc" in - *.el) - # keep original source filename without the hash - local filename=$(basename "$curSrc") - filename="''${filename:33}" - cp $curSrc $filename - chmod +w $filename - sourceRoot="." - ;; - *) - _defaultUnpack "$curSrc" - ;; - esac - ''; - - buildInputs = [emacs texinfo] ++ packageRequires ++ buildInputs; - propagatedBuildInputs = packageRequires; - propagatedUserEnvPkgs = packageRequires; - - inherit setupHook; - - doCheck = false; - - meta = { - broken = false; - platforms = emacs.meta.platforms; - } // optionalAttrs ((args.src.meta.homepage or "") != "") { - homepage = args.src.meta.homepage; - } // meta; -} - -// optionalAttrs (emacs.withNativeCompilation or false) { - - LIBRARY_PATH = "${getLib stdenv.cc.libc}/lib"; - - nativeBuildInputs = [ gcc ]; - - addEmacsNativeLoadPath = true; - - postInstall = '' - # Besides adding the output directory to the native load path, make sure - # the current package's elisp files are in the load path, otherwise - # (require 'file-b) from file-a.el in the same package will fail. - mkdir -p $out/share/emacs/native-lisp - source ${./emacs-funcs.sh} - addEmacsVars "$out" - - find $out/share/emacs -type f -name '*.el' -print0 \ - | xargs -0 -I {} -n 1 -P $NIX_BUILD_CORES sh -c \ - "emacs --batch --eval '(setq large-file-warning-threshold nil)' -f batch-native-compile {} || true" - ''; -} - -// removeAttrs args handledArgs)) diff --git a/pkgs/build-support/emacs/melpa.nix b/pkgs/build-support/emacs/melpa.nix deleted file mode 100644 index c8f6567049180..0000000000000 --- a/pkgs/build-support/emacs/melpa.nix +++ /dev/null @@ -1,125 +0,0 @@ -# builder for Emacs packages built for packages.el -# using MELPA package-build.el - -{ lib, stdenv, fetchFromGitHub, emacs, texinfo, writeText, gcc }: - -let - genericBuild = import ./generic.nix { inherit lib stdenv emacs texinfo writeText gcc; }; - - packageBuild = stdenv.mkDerivation { - name = "package-build"; - src = fetchFromGitHub { - owner = "melpa"; - repo = "package-build"; - rev = "c48aa078c01b4f07b804270c4583a0a58ffea1c0"; - sha256 = "sha256-MzPj375upIiYXdQR+wWXv3A1zMqbSrZlH0taLuxx/1M="; - }; - - patches = [ ./package-build-dont-use-mtime.patch ]; - - dontConfigure = true; - dontBuild = true; - - installPhase = " - mkdir -p $out - cp -r * $out - "; - }; - -in - -{ /* - pname: Nix package name without special symbols and without version or - "emacs-" prefix. - */ - pname - /* - ename: Original Emacs package name, possibly containing special symbols. - Default: pname - */ -, ename ? pname -, version - /* - commit: Optional package history commit. - Default: src.rev or "unknown" - This will be written into the generated package but it is not needed during - the build process. - */ -, commit ? (args.src.rev or "unknown") - /* - files: Optional recipe property specifying the files used to build the package. - If null, do not set it in recipe, keeping the default upstream behaviour. - Default: null - */ -, files ? null - /* - recipe: Optional MELPA recipe. - Default: a minimally functional recipe - */ -, recipe ? (writeText "${pname}-recipe" '' - (${ename} :fetcher git :url "" - ${lib.optionalString (files != null) ":files ${files}"}) - '') -, meta ? {} -, ... -}@args: - -genericBuild ({ - - elpa2nix = ./elpa2nix.el; - melpa2nix = ./melpa2nix.el; - - inherit packageBuild commit ename recipe; - - preUnpack = '' - mkdir -p "$NIX_BUILD_TOP/recipes" - if [ -n "$recipe" ]; then - cp "$recipe" "$NIX_BUILD_TOP/recipes/$ename" - fi - - ln -s "$packageBuild" "$NIX_BUILD_TOP/package-build" - - mkdir -p "$NIX_BUILD_TOP/packages" - ''; - - postUnpack = '' - mkdir -p "$NIX_BUILD_TOP/working" - ln -s "$NIX_BUILD_TOP/$sourceRoot" "$NIX_BUILD_TOP/working/$ename" - ''; - - buildPhase = '' - runHook preBuild - - cd "$NIX_BUILD_TOP" - - emacs --batch -Q \ - -L "$NIX_BUILD_TOP/package-build" \ - -l "$melpa2nix" \ - -f melpa2nix-build-package \ - $ename $version $commit - - runHook postBuild - ''; - - installPhase = '' - runHook preInstall - - archive="$NIX_BUILD_TOP/packages/$ename-$version.el" - if [ ! -f "$archive" ]; then - archive="$NIX_BUILD_TOP/packages/$ename-$version.tar" - fi - - emacs --batch -Q \ - -l "$elpa2nix" \ - -f elpa2nix-install-package \ - "$archive" "$out/share/emacs/site-lisp/elpa" - - runHook postInstall - ''; - - meta = { - homepage = args.src.meta.homepage or "https://melpa.org/#/${pname}"; - } // meta; -} - -// removeAttrs args [ "meta" ]) diff --git a/pkgs/build-support/emacs/melpa2nix.el b/pkgs/build-support/emacs/melpa2nix.el deleted file mode 100644 index 3de77dbf5e5c6..0000000000000 --- a/pkgs/build-support/emacs/melpa2nix.el +++ /dev/null @@ -1,32 +0,0 @@ -(require 'package) -(package-initialize) - -(require 'package-recipe) -(require 'package-build) - -(setq package-build-working-dir (expand-file-name "working/")) -(setq package-build-archive-dir (expand-file-name "packages/")) -(setq package-build-recipes-dir (expand-file-name "recipes/")) - -;; Allow installing package tarfiles larger than 10MB -(setq large-file-warning-threshold nil) - -(defun melpa2nix-build-package-1 (rcp) - (let* ((default-directory (package-recipe--working-tree rcp))) - (unwind-protect - (let ((files (package-build-expand-files-spec rcp t))) - (unless files - (error "Unable to find files matching recipe patterns")) - (if (> (length files) 1) - (package-build--build-multi-file-package rcp files) - (package-build--build-single-file-package rcp files)))))) - -(defun melpa2nix-build-package () - (unless noninteractive - (error "`melpa2nix-build-package' is to be used only with -batch")) - (pcase command-line-args-left - (`(,package ,version ,commit) - (let ((recipe (package-recipe-lookup package))) - (setf (oref recipe commit) commit) - (setf (oref recipe version) version) - (melpa2nix-build-package-1 recipe))))) diff --git a/pkgs/build-support/emacs/mk-wrapper-subdirs.el b/pkgs/build-support/emacs/mk-wrapper-subdirs.el deleted file mode 100644 index 7d30400a5c65f..0000000000000 --- a/pkgs/build-support/emacs/mk-wrapper-subdirs.el +++ /dev/null @@ -1,6 +0,0 @@ -(defmacro mk-subdirs-expr (path) - `(setq load-path - (delete-dups (append '(,path) - ',(let ((default-directory path)) - (normal-top-level-add-subdirs-to-load-path)) - load-path)))) diff --git a/pkgs/build-support/emacs/package-build-dont-use-mtime.patch b/pkgs/build-support/emacs/package-build-dont-use-mtime.patch deleted file mode 100644 index 1ace7771ea3ac..0000000000000 --- a/pkgs/build-support/emacs/package-build-dont-use-mtime.patch +++ /dev/null @@ -1,21 +0,0 @@ -diff --git a/package-build.el b/package-build.el -index 29cdb61..c19be1b 100644 ---- a/package-build.el -+++ b/package-build.el -@@ -923,7 +923,6 @@ DIRECTORY is a temporary directory that contains the directory - that is put in the tarball." - (let* ((name (oref rcp name)) - (version (oref rcp version)) -- (time (oref rcp time)) - (tar (expand-file-name (concat name "-" version ".tar") - package-build-archive-dir)) - (dir (concat name "-" version))) -@@ -939,7 +938,7 @@ that is put in the tarball." - ;; prevent a reproducible tarball as described at - ;; https://reproducible-builds.org/docs/archives. - "--sort=name" -- (format "--mtime=@%d" time) -+ "--mtime=@0" - "--owner=0" "--group=0" "--numeric-owner" - "--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime")) - (when (and package-build-verbose noninteractive) diff --git a/pkgs/build-support/emacs/trivial.nix b/pkgs/build-support/emacs/trivial.nix deleted file mode 100644 index 11c28c0133e40..0000000000000 --- a/pkgs/build-support/emacs/trivial.nix +++ /dev/null @@ -1,28 +0,0 @@ -# trivial builder for Emacs packages - -{ callPackage, lib, ... }@envargs: - -args: - -callPackage ./generic.nix envargs ({ - buildPhase = '' - runHook preBuild - - emacs -L . --batch -f batch-byte-compile *.el - - runHook postBuild - ''; - - installPhase = '' - runHook preInstall - - LISPDIR=$out/share/emacs/site-lisp - install -d $LISPDIR - install *.el *.elc $LISPDIR - emacs --batch -l package --eval "(package-generate-autoloads \"${args.pname}\" \"$LISPDIR\")" - - runHook postInstall - ''; -} - -// args) diff --git a/pkgs/build-support/emacs/wrapper.nix b/pkgs/build-support/emacs/wrapper.nix deleted file mode 100644 index 59a694286d09e..0000000000000 --- a/pkgs/build-support/emacs/wrapper.nix +++ /dev/null @@ -1,236 +0,0 @@ -/* - -# Usage - -`emacs.pkgs.withPackages` takes a single argument: a function from a package -set to a list of packages (the packages that will be available in -Emacs). For example, -``` -emacs.pkgs.withPackages (epkgs: [ epkgs.evil epkgs.magit ]) -``` -All the packages in the list should come from the provided package -set. It is possible to add any package to the list, but the provided -set is guaranteed to have consistent dependencies and be built with -the correct version of Emacs. - -# Overriding - -`emacs.pkgs.withPackages` inherits the package set which contains it, so the -correct way to override the provided package set is to override the -set which contains `emacs.pkgs.withPackages`. For example, to override -`emacs.pkgs.emacs.pkgs.withPackages`, -``` -let customEmacsPackages = - emacs.pkgs.overrideScope (self: super: { - # use a custom version of emacs - emacs = ...; - # use the unstable MELPA version of magit - magit = self.melpaPackages.magit; - }); -in customEmacsPackages.withPackages (epkgs: [ epkgs.evil epkgs.magit ]) -``` - -*/ - -{ lib, lndir, makeBinaryWrapper, runCommand, gcc }: -self: -let - inherit (self) emacs; - withNativeCompilation = emacs.withNativeCompilation or false; - withTreeSitter = emacs.withTreeSitter or false; -in -packagesFun: # packages explicitly requested by the user -let - explicitRequires = - if lib.isFunction packagesFun - then packagesFun self - else packagesFun; -in -runCommand - (lib.appendToName "with-packages" emacs).name - { - inherit emacs explicitRequires; - nativeBuildInputs = [ emacs lndir makeBinaryWrapper ]; - - preferLocalBuild = true; - allowSubstitutes = false; - - # Store all paths we want to add to emacs here, so that we only need to add - # one path to the load lists - deps = runCommand "emacs-packages-deps" - ({ - inherit explicitRequires lndir emacs; - nativeBuildInputs = lib.optional withNativeCompilation gcc; - } // lib.optionalAttrs withNativeCompilation { - inherit (emacs) LIBRARY_PATH; - }) - '' - findInputsOld() { - local pkg="$1"; shift - local var="$1"; shift - local propagatedBuildInputsFiles=("$@") - - # TODO(@Ericson2314): Restore using associative array once Darwin - # nix-shell doesn't use impure bash. This should replace the O(n) - # case with an O(1) hash map lookup, assuming bash is implemented - # well :D. - local varSlice="$var[*]" - # ''${..-} to hack around old bash empty array problem - case "''${!varSlice-}" in - *" $pkg "*) return 0 ;; - esac - unset -v varSlice - - eval "$var"'+=("$pkg")' - - if ! [ -e "$pkg" ]; then - echo "build input $pkg does not exist" >&2 - exit 1 - fi - - local file - for file in "''${propagatedBuildInputsFiles[@]}"; do - file="$pkg/nix-support/$file" - [[ -f "$file" ]] || continue - - local pkgNext - for pkgNext in $(< "$file"); do - findInputsOld "$pkgNext" "$var" "''${propagatedBuildInputsFiles[@]}" - done - done - } - mkdir -p $out/bin - mkdir -p $out/share/emacs/site-lisp - ${lib.optionalString withNativeCompilation '' - mkdir -p $out/share/emacs/native-lisp - ''} - ${lib.optionalString withTreeSitter '' - mkdir -p $out/lib - ''} - - local requires - for pkg in $explicitRequires; do - findInputsOld $pkg requires propagated-user-env-packages - done - # requires now holds all requested packages and their transitive dependencies - - linkPath() { - local pkg=$1 - local origin_path=$2 - local dest_path=$3 - - # Add the path to the search path list, but only if it exists - if [[ -d "$pkg/$origin_path" ]]; then - $lndir/bin/lndir -silent "$pkg/$origin_path" "$out/$dest_path" - fi - } - - linkEmacsPackage() { - linkPath "$1" "bin" "bin" - linkPath "$1" "share/emacs/site-lisp" "share/emacs/site-lisp" - ${lib.optionalString withNativeCompilation '' - linkPath "$1" "share/emacs/native-lisp" "share/emacs/native-lisp" - ''} - ${lib.optionalString withTreeSitter '' - linkPath "$1" "lib" "lib" - ''} - } - - # Iterate over the array of inputs (avoiding nix's own interpolation) - for pkg in "''${requires[@]}"; do - linkEmacsPackage $pkg - done - - siteStart="$out/share/emacs/site-lisp/site-start.el" - siteStartByteCompiled="$siteStart"c - subdirs="$out/share/emacs/site-lisp/subdirs.el" - subdirsByteCompiled="$subdirs"c - - # A dependency may have brought the original siteStart or subdirs, delete - # it and create our own - # Begin the new site-start.el by loading the original, which sets some - # NixOS-specific paths. Paths are searched in the reverse of the order - # they are specified in, so user and system profile paths are searched last. - # - # NOTE: Avoid displaying messages early at startup by binding - # inhibit-message to t. This would prevent the Emacs GUI from showing up - # prematurely. The messages would still be logged to the *Messages* - # buffer. - rm -f $siteStart $siteStartByteCompiled $subdirs $subdirsByteCompiled - cat >"$siteStart" <<EOF - (let ((inhibit-message t)) - (load "$emacs/share/emacs/site-lisp/site-start")) - ;; "$out/share/emacs/site-lisp" is added to load-path in wrapper.sh - ;; "$out/share/emacs/native-lisp" is added to native-comp-eln-load-path in wrapper.sh - (add-to-list 'exec-path "$out/bin") - ${lib.optionalString withTreeSitter '' - (add-to-list 'treesit-extra-load-path "$out/lib/") - ''} - EOF - - # Generate a subdirs.el that statically adds all subdirectories to load-path. - $emacs/bin/emacs \ - --batch \ - --load ${./mk-wrapper-subdirs.el} \ - --eval "(prin1 (macroexpand-1 '(mk-subdirs-expr \"$out/share/emacs/site-lisp\")))" \ - > "$subdirs" - - # Byte-compiling improves start-up time only slightly, but costs nothing. - $emacs/bin/emacs --batch -f batch-byte-compile "$siteStart" "$subdirs" - - ${lib.optionalString withNativeCompilation '' - $emacs/bin/emacs --batch \ - --eval "(add-to-list 'native-comp-eln-load-path \"$out/share/emacs/native-lisp/\")" \ - -f batch-native-compile "$siteStart" "$subdirs" - ''} - ''; - - inherit (emacs) meta; - } - '' - mkdir -p "$out/bin" - - # Wrap emacs and friends so they find our site-start.el before the original. - for prog in $emacs/bin/*; do # */ - local progname=$(basename "$prog") - rm -f "$out/bin/$progname" - - substitute ${./wrapper.sh} $out/bin/$progname \ - --subst-var-by bash ${emacs.stdenv.shell} \ - --subst-var-by wrapperSiteLisp "$deps/share/emacs/site-lisp" \ - --subst-var-by wrapperSiteLispNative "$deps/share/emacs/native-lisp" \ - --subst-var prog - chmod +x $out/bin/$progname - # Create a “NOP” binary wrapper for the pure sake of it becoming a - # non-shebang, actual binary. See the makeBinaryWrapper docs for rationale - # (summary: it allows you to use emacs as a shebang itself on Darwin, - # e.g. #!$ {emacs}/bin/emacs --script) - wrapProgramBinary $out/bin/$progname - done - - # Wrap MacOS app - # this has to pick up resources and metadata - # to recognize it as an "app" - if [ -d "$emacs/Applications/Emacs.app" ]; then - mkdir -p $out/Applications/Emacs.app/Contents/MacOS - cp -r $emacs/Applications/Emacs.app/Contents/Info.plist \ - $emacs/Applications/Emacs.app/Contents/PkgInfo \ - $emacs/Applications/Emacs.app/Contents/Resources \ - $out/Applications/Emacs.app/Contents - - - substitute ${./wrapper.sh} $out/Applications/Emacs.app/Contents/MacOS/Emacs \ - --subst-var-by bash ${emacs.stdenv.shell} \ - --subst-var-by wrapperSiteLisp "$deps/share/emacs/site-lisp" \ - --subst-var-by wrapperSiteLispNative "$deps/share/emacs/native-lisp" \ - --subst-var-by prog "$emacs/Applications/Emacs.app/Contents/MacOS/Emacs" - chmod +x $out/Applications/Emacs.app/Contents/MacOS/Emacs - wrapProgramBinary $out/Applications/Emacs.app/Contents/MacOS/Emacs - fi - - mkdir -p $out/share - # Link icons and desktop files into place - for dir in applications icons info man; do - ln -s $emacs/share/$dir $out/share/$dir - done - '' diff --git a/pkgs/build-support/emacs/wrapper.sh b/pkgs/build-support/emacs/wrapper.sh deleted file mode 100644 index 44762bd4582b0..0000000000000 --- a/pkgs/build-support/emacs/wrapper.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!@bash@ - -IFS=: - -newLoadPath=() -newNativeLoadPath=() -addedNewLoadPath= -addedNewNativeLoadPath= - -if [[ -n $EMACSLOADPATH ]] -then - while read -rd: entry - do - if [[ -z $entry && -z $addedNewLoadPath ]] - then - newLoadPath+=(@wrapperSiteLisp@) - addedNewLoadPath=1 - fi - newLoadPath+=("$entry") - done <<< "$EMACSLOADPATH:" -else - newLoadPath+=(@wrapperSiteLisp@) - newLoadPath+=("") -fi - -# NOTE: Even though we treat EMACSNATIVELOADPATH like EMACSLOADPATH in -# this wrapper, empty elements in EMACSNATIVELOADPATH have no special -# meaning for Emacs. Only non-empty elements in EMACSNATIVELOADPATH -# will be prepended to native-comp-eln-load-path. -# https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/startup.el?id=3685387e609753293c4518be75e77c659c3b2d8d#n599 -if [[ -n $EMACSNATIVELOADPATH ]] -then - while read -rd: entry - do - if [[ -z $entry && -z $addedNewNativeLoadPath ]] - then - newNativeLoadPath+=(@wrapperSiteLispNative@) - addedNewNativeLoadPath=1 - fi - newNativeLoadPath+=("$entry") - done <<< "$EMACSNATIVELOADPATH:" -else - newNativeLoadPath+=(@wrapperSiteLispNative@) - newNativeLoadPath+=("") -fi - -export EMACSLOADPATH="${newLoadPath[*]}" -export emacsWithPackages_siteLisp=@wrapperSiteLisp@ - -export EMACSNATIVELOADPATH="${newNativeLoadPath[*]}" -export emacsWithPackages_siteLispNative=@wrapperSiteLispNative@ - -exec @prog@ "$@" diff --git a/pkgs/build-support/fetchpatch/default.nix b/pkgs/build-support/fetchpatch/default.nix index a3ca6685147d3..97b3661bb2d46 100644 --- a/pkgs/build-support/fetchpatch/default.nix +++ b/pkgs/build-support/fetchpatch/default.nix @@ -14,6 +14,7 @@ , includes ? [] , revert ? false , postFetch ? "" +, nativeBuildInputs ? [] , ... }@args: let @@ -29,6 +30,7 @@ in lib.throwIfNot (excludes == [] || includes == []) "fetchpatch: cannot use excludes and includes simultaneously" fetchurl ({ + nativeBuildInputs = [ patchutils ] ++ nativeBuildInputs; postFetch = '' tmpfile="$TMPDIR/patch" @@ -48,12 +50,12 @@ fetchurl ({ set -e mv "$tmpfile" "$out" - "${patchutils}/bin/lsdiff" \ + lsdiff \ ${lib.optionalString (relative != null) "-p1 -i ${lib.escapeShellArg relative}/'*'"} \ "$out" \ | sort -u | sed -e 's/[*?]/\\&/g' \ | xargs -I{} \ - "${patchutils}/bin/filterdiff" \ + filterdiff \ --include={} \ --strip=${toString stripLen} \ ${lib.optionalString (extraPrefix != null) '' @@ -70,7 +72,7 @@ fetchurl ({ exit 1 fi - ${patchutils}/bin/filterdiff \ + filterdiff \ -p1 \ ${builtins.toString (builtins.map (x: "-x ${lib.escapeShellArg x}") excludes)} \ ${builtins.toString (builtins.map (x: "-i ${lib.escapeShellArg x}") includes)} \ @@ -84,10 +86,10 @@ fetchurl ({ exit 1 fi '' + lib.optionalString revert '' - ${patchutils}/bin/interdiff "$out" /dev/null > "$tmpfile" + interdiff "$out" /dev/null > "$tmpfile" mv "$tmpfile" "$out" '' + postFetch; } // builtins.removeAttrs args [ "relative" "stripLen" "decode" "extraPrefix" "excludes" "includes" "revert" - "postFetch" + "postFetch" "nativeBuildInputs" ]) diff --git a/pkgs/build-support/fetchpatch/tests.nix b/pkgs/build-support/fetchpatch/tests.nix index 0a27f1bc70e7a..b7352fff7f925 100644 --- a/pkgs/build-support/fetchpatch/tests.nix +++ b/pkgs/build-support/fetchpatch/tests.nix @@ -7,7 +7,7 @@ in { simple = testers.invalidateFetcherByDrvHash fetchpatch { url = "https://github.com/facebook/zstd/pull/2724/commits/e1f85dbca3a0ed5ef06c8396912a0914db8dea6a.patch"; - sha256 = if isFetchpatch2 then "sha256-01BrkHLye4KOdqCw3tv7AJzIF6578pl2fl270TJFTmw=" else "sha256-PuYAqnJWAE+L9bsroOnnBGJhERW8LHrGSLtIEkKU9vg="; + sha256 = if isFetchpatch2 then "sha256-w4yU0wt64d0WkuBQPeGf8vn5TH6qSBJvNIgka9QK+/Q=" else "sha256-PuYAqnJWAE+L9bsroOnnBGJhERW8LHrGSLtIEkKU9vg="; }; relative = testers.invalidateFetcherByDrvHash fetchpatch { diff --git a/pkgs/build-support/go/module.nix b/pkgs/build-support/go/module.nix index bc28fbf6fc420..a5e722b0ac08e 100644 --- a/pkgs/build-support/go/module.nix +++ b/pkgs/build-support/go/module.nix @@ -218,8 +218,7 @@ let buildGoDir() { local cmd="$1" dir="$2" - . $TMPDIR/buildFlagsArray - + declare -ga buildFlagsArray declare -a flags flags+=($buildFlags "''${buildFlagsArray[@]}") flags+=(''${tags:+-tags=''${tags// /,}}) @@ -258,11 +257,6 @@ let buildFlagsArray+=(-x) fi - if [ ''${#buildFlagsArray[@]} -ne 0 ]; then - declare -p buildFlagsArray > $TMPDIR/buildFlagsArray - else - touch $TMPDIR/buildFlagsArray - fi if [ -z "$enableParallelBuilding" ]; then export NIX_BUILD_CORES=1 fi diff --git a/pkgs/build-support/kernel/make-initrd.nix b/pkgs/build-support/kernel/make-initrd.nix index 9c27a142f4b65..5f8d1eee8ce4d 100644 --- a/pkgs/build-support/kernel/make-initrd.nix +++ b/pkgs/build-support/kernel/make-initrd.nix @@ -56,7 +56,7 @@ in , prepend ? [] # Whether to wrap the initramfs in a u-boot image. -, makeUInitrd ? stdenvNoCC.hostPlatform.linux-kernel.target == "uImage" +, makeUInitrd ? stdenvNoCC.hostPlatform.linux-kernel.target or "dummy" == "uImage" # If generating a u-boot image, the architecture to use. The default # guess may not align with u-boot's nomenclature correctly, so it can @@ -75,11 +75,9 @@ let toValidStoreName = x: with builtins; lib.concatStringsSep "-" (filter (x: !(isList x)) (split "[^a-zA-Z0-9_=.?-]+" x)); -in stdenvNoCC.mkDerivation rec { +in stdenvNoCC.mkDerivation (rec { inherit name makeUInitrd extension uInitrdArch prepend; - ${if makeUInitrd then "uInitrdCompression" else null} = uInitrdCompression; - builder = ./make-initrd.sh; nativeBuildInputs = [ perl libarchive ] @@ -110,4 +108,6 @@ in stdenvNoCC.mkDerivation rec { contents (lib.range 0 (lib.length contents - 1)); pathsFromGraph = ./paths-from-graph.pl; -} +} // lib.optionalAttrs makeUInitrd { + uInitrdCompression = uInitrdCompression; +}) diff --git a/pkgs/build-support/make-desktopitem/default.nix b/pkgs/build-support/make-desktopitem/default.nix index ccceb23256b6f..9cae8204c6a83 100644 --- a/pkgs/build-support/make-desktopitem/default.nix +++ b/pkgs/build-support/make-desktopitem/default.nix @@ -108,11 +108,12 @@ let renderAction = name: attrs: renderSection "Desktop Action ${name}" (preprocessAction attrs); actionsRendered = lib.mapAttrsToList renderAction actions; + extension = if type == "Directory" then "directory" else "desktop"; content = [ mainSectionRendered ] ++ actionsRendered; in writeTextFile { - name = "${name}.desktop"; - destination = "/share/applications/${name}.desktop"; + name = "${name}.${extension}"; + destination = "/share/applications/${name}.${extension}"; text = builtins.concatStringsSep "\n" content; checkPhase = ''${buildPackages.desktop-file-utils}/bin/desktop-file-validate "$target"''; }) diff --git a/pkgs/build-support/node/fetch-npm-deps/default.nix b/pkgs/build-support/node/fetch-npm-deps/default.nix index d86fc90c6c7d1..a001f80b113ce 100644 --- a/pkgs/build-support/node/fetch-npm-deps/default.nix +++ b/pkgs/build-support/node/fetch-npm-deps/default.nix @@ -142,7 +142,7 @@ meta = with lib; { description = "Prefetch dependencies from npm (for use with `fetchNpmDeps`)"; mainProgram = "prefetch-npm-deps"; - maintainers = with maintainers; [ lilyinstarlight winter ]; + maintainers = with maintainers; [ winter ]; license = licenses.mit; }; }; diff --git a/pkgs/build-support/rust/build-rust-crate/configure-crate.nix b/pkgs/build-support/rust/build-rust-crate/configure-crate.nix index ab872bac854f8..c348885e44cab 100644 --- a/pkgs/build-support/rust/build-rust-crate/configure-crate.nix +++ b/pkgs/build-support/rust/build-rust-crate/configure-crate.nix @@ -14,6 +14,7 @@ , crateLicenseFile , crateLinks , crateName +, crateType , crateReadme , crateRenames , crateRepository @@ -194,7 +195,7 @@ in '' export CARGO_FEATURE_$feature=1 done - target/build/${crateName}/build_script_build > target/build/${crateName}.opt + target/build/${crateName}/build_script_build | tee target/build/${crateName}.opt ) set +e @@ -209,6 +210,11 @@ in '' EXTRA_LINK_LIBS=$(sed -n "s/^cargo::\{0,1\}rustc-link-lib=\(.*\)/\1/p" target/build/${crateName}.opt | tr '\n' ' ') EXTRA_LINK_SEARCH=$(sed -n "s/^cargo::\{0,1\}rustc-link-search=\(.*\)/\1/p" target/build/${crateName}.opt | tr '\n' ' ' | sort -u) + ${lib.optionalString (lib.elem "cdylib" crateType) '' + CRATE_TYPE_IS_CDYLIB="true" + EXTRA_CDYLIB_LINK_ARGS=$(sed -n "s/^cargo::\{0,1\}rustc-cdylib-link-arg=\(.*\)/-C link-arg=\1/p" target/build/${crateName}.opt | tr '\n' ' ') +''} + # We want to read part of every line that has cargo:rustc-env= prefix and # export it as environment variables. This turns out tricky if the lines # have spaces: we can't wrap the command in double quotes as that captures diff --git a/pkgs/build-support/rust/build-rust-crate/default.nix b/pkgs/build-support/rust/build-rust-crate/default.nix index d6369055cc53b..841e8e86cbfb1 100644 --- a/pkgs/build-support/rust/build-rust-crate/default.nix +++ b/pkgs/build-support/rust/build-rust-crate/default.nix @@ -357,7 +357,7 @@ crate_: lib.makeOverridable configurePhase = configureCrate { - inherit crateName buildDependencies completeDeps completeBuildDeps crateDescription + inherit crateName crateType buildDependencies completeDeps completeBuildDeps crateDescription crateFeatures crateRenames libName build workspace_member release libPath crateVersion crateLinks extraLinkFlags extraRustcOptsForBuildRs crateLicense crateLicenseFile crateReadme crateRepository crateRustVersion diff --git a/pkgs/build-support/rust/build-rust-crate/lib.sh b/pkgs/build-support/rust/build-rust-crate/lib.sh index 0181ae432c85b..36ddc9ac23c4f 100644 --- a/pkgs/build-support/rust/build-rust-crate/lib.sh +++ b/pkgs/build-support/rust/build-rust-crate/lib.sh @@ -114,6 +114,12 @@ setup_link_paths() { tr '\n' ' ' < target/link > target/link_ LINK=$(cat target/link_) fi + + # Add "rustc-cdylib-link-arg" as linker arguments + # https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-cdylib-link-arg + if [[ -n "$CRATE_TYPE_IS_CDYLIB" ]]; then + EXTRA_BUILD+=" $EXTRA_CDYLIB_LINK_ARGS" + fi } search_for_bin_path() { diff --git a/pkgs/build-support/rust/default-crate-overrides.nix b/pkgs/build-support/rust/default-crate-overrides.nix index d8f1bfaf4447b..f974ff3adc33d 100644 --- a/pkgs/build-support/rust/default-crate-overrides.nix +++ b/pkgs/build-support/rust/default-crate-overrides.nix @@ -1,46 +1,48 @@ { lib , stdenv +, alsa-lib , atk -, pkg-config +, autoconf +, automake +, cairo +, capnproto +, clang +, cmake , curl , darwin -, libgit2 -, gtk3 -, libssh2 -, openssl -, sqlite -, zlib , dbus , dbus-glib +, fontconfig +, foundationdb +, freetype , gdk-pixbuf -, cairo -, python3 -, libsodium -, postgresql +, glib , gmp , gobject-introspection -, foundationdb -, capnproto -, nettle +, graphene +, gtk3 , gtk4 -, clang -, llvmPackages +, libevdev +, libgit2 +, libsodium +, libsoup_3 +, libssh2 +, libtool , linux-pam +, llvmPackages +, nettle +, openssl , pango -, cmake -, glib -, freetype -, fontconfig -, rdkafka -, udev -, libevdev -, alsa-lib -, graphene +, pkg-config +, postgresql , protobuf -, autoconf -, automake -, libtool +, python3 +, rdkafka , seatd # =libseat +, sqlite +, udev +, webkitgtk_4_1 +, zlib , ... }: @@ -93,7 +95,10 @@ in nativeBuildInputs = [ pkg-config ] ++ lib.optionals (stdenv.buildPlatform.config != stdenv.hostPlatform.config) [ - python3 autoconf automake libtool + python3 + autoconf + automake + libtool ]; buildInputs = [ libevdev ]; @@ -132,21 +137,34 @@ in }; gobject-sys = attrs: { + nativeBuildInputs = [ pkg-config ]; buildInputs = [ dbus-glib ]; }; gio-sys = attrs: { + nativeBuildInputs = [ pkg-config ]; buildInputs = [ dbus-glib ]; }; - gdk-pixbuf-sys = attrs: { - buildInputs = [ dbus-glib ]; + gdk-pixbuf = attrs: { + buildInputs = [ dbus-glib gdk-pixbuf ]; }; - gdk-pixbuf = attrs: { + gdk-pixbuf-sys = attrs: { + nativeBuildInputs = [ pkg-config ]; buildInputs = [ gdk-pixbuf ]; }; + gdk-sys = attrs: { + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ gtk3 ]; # libgdk-3 + }; + + gdkx11-sys = attrs: { + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ gtk3 ]; + }; + gtk-sys = attrs: { buildInputs = [ gtk3 ]; nativeBuildInputs = [ pkg-config ]; @@ -203,6 +221,11 @@ in buildInputs = [ graphene ]; }; + javascriptcore-rs-sys = attrs: { + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ webkitgtk_4_1 ]; + }; + nettle-sys = attrs: { nativeBuildInputs = [ pkg-config ]; buildInputs = [ nettle clang ]; @@ -302,6 +325,11 @@ in buildInputs = [ freetype fontconfig ]; }; + soup3-sys = attrs: { + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ libsoup_3 ]; + }; + thrussh-libsodium = attrs: { nativeBuildInputs = [ pkg-config ]; buildInputs = [ libsodium ]; @@ -311,6 +339,11 @@ in nativeBuildInputs = [ protobuf ]; }; + webkit2gtk-sys = attrs: { + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ webkitgtk_4_1 ]; + }; + xcb = attrs: { buildInputs = [ python3 ]; }; diff --git a/pkgs/build-support/rust/hooks/maturin-build-hook.sh b/pkgs/build-support/rust/hooks/maturin-build-hook.sh index b3cc1ced79647..c1e701425f00d 100644 --- a/pkgs/build-support/rust/hooks/maturin-build-hook.sh +++ b/pkgs/build-support/rust/hooks/maturin-build-hook.sh @@ -3,6 +3,9 @@ maturinBuildHook() { runHook preBuild + # Put the wheel to dist/ so that regular Python tooling can find it. + local dist="$PWD/dist" + if [ ! -z "${buildAndTestSubdir-}" ]; then pushd "${buildAndTestSubdir}" fi @@ -16,6 +19,7 @@ maturinBuildHook() { --manylinux off \ --strip \ --release \ + --out "$dist" \ ${maturinBuildFlags-} ) @@ -23,10 +27,6 @@ maturinBuildHook() { popd fi - # Move the wheel to dist/ so that regular Python tooling can find it. - mkdir -p dist - mv ${cargoRoot:+$cargoRoot/}target/wheels/*.whl dist/ - # These are python build hooks and may depend on ./dist runHook postBuild diff --git a/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh b/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh index e103fe77d9be7..0b03460eacb65 100644 --- a/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh +++ b/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh @@ -23,10 +23,13 @@ fixDarwinDylibNames() { for fn in "$@"; do if [ -L "$fn" ]; then continue; fi echo "$fn: fixing dylib" + set +e int_out=$(@targetPrefix@install_name_tool -id "$fn" "${flags[@]}" "$fn" 2>&1) result=$? + set -e if [ "$result" -ne 0 ] && - ! grep "shared library stub file and can't be changed" <<< "$out" + ! grep -q -e "shared library stub file and can't be changed" \ + -e "is not a Mach-O file" <<< "$int_out" then echo "$int_out" >&2 exit "$result" diff --git a/pkgs/build-support/setup-hooks/install-shell-files.sh b/pkgs/build-support/setup-hooks/install-shell-files.sh index 194b408b10501..4f4e215da4df2 100644 --- a/pkgs/build-support/setup-hooks/install-shell-files.sh +++ b/pkgs/build-support/setup-hooks/install-shell-files.sh @@ -219,6 +219,11 @@ installShellCompletion() { else install -Dm644 -T "$arg" "$outPath" fi || return + + if [ ! -s "$outPath" ]; then + echo "installShellCompletion: error: installed shell completion file \`$outPath' does not exist or has zero size" >&2 + return 1 + fi # Clear the per-path flags name= done diff --git a/pkgs/build-support/writers/scripts.nix b/pkgs/build-support/writers/scripts.nix index 93fac09c07ba5..bceac1b0c9590 100644 --- a/pkgs/build-support/writers/scripts.nix +++ b/pkgs/build-support/writers/scripts.nix @@ -485,7 +485,7 @@ rec { # returns an executable # # Example: - # writeJS "example" { libraries = [ pkgs.nodePackages.uglify-js ]; } '' + # writeJS "example" { libraries = [ pkgs.uglify-js ]; } '' # var UglifyJS = require("uglify-js"); # var code = "function add(first, second) { return first + second; }"; # var result = UglifyJS.minify(code); |