|
41 | 41 | warnUndeclaredOptions = true; |
42 | 42 | fetchedSourceNameDefault = "full"; |
43 | 43 | doCheckByDefault = false; |
44 | | - # replaceStdenv = ({ pkgs }: pkgs.clangStdenv); |
| 44 | + replaceStdenv = |
| 45 | + { pkgs }: |
| 46 | + let |
| 47 | + customStdenv = |
| 48 | + stdenv: |
| 49 | + stdenv.override (old: { |
| 50 | + allowedRequisites = null; |
| 51 | + mkDerivationFromStdenv = |
| 52 | + stdenvSelf: |
| 53 | + let |
| 54 | + defaultMkDerivationFromStdenv = |
| 55 | + stdenv: |
| 56 | + (import (pkgs.path + "/pkgs/stdenv/generic/make-derivation.nix") { |
| 57 | + inherit (pkgs) lib config; |
| 58 | + } stdenv).mkDerivation; |
| 59 | + mkDerivationSuper = (old.mkDerivationFromStdenv or defaultMkDerivationFromStdenv) stdenvSelf; |
| 60 | + in |
| 61 | + args: |
| 62 | + let |
| 63 | + extraCompile = " -pipe"; |
| 64 | + extraLink = " -Wl,-z,pack-relative-relocs"; |
| 65 | + |
| 66 | + # Function to apply flags to either env.FLAG or top-level FLAG |
| 67 | + applyFlags = currentAttrs: flagName: flagsToAdd: |
| 68 | + let |
| 69 | + valEnv = if currentAttrs ? env then (currentAttrs.env.${flagName} or "") else ""; |
| 70 | + valTop = if currentAttrs ? ${flagName} then (currentAttrs.${flagName}) else ""; |
| 71 | + # Combine existing env + top-level + new flags |
| 72 | + combined = toString valEnv + " " + toString valTop + flagsToAdd; |
| 73 | + in |
| 74 | + # ALWAYS put flags in env and remove from top-level. |
| 75 | + # This avoids conflicts if overrideAttrs later introduces env/structured attrs. |
| 76 | + # Legacy mkDerivation supports env vars too. |
| 77 | + (builtins.removeAttrs currentAttrs [ flagName ]) // { |
| 78 | + env = (currentAttrs.env or {}) // { |
| 79 | + ${flagName} = combined; |
| 80 | + }; |
| 81 | + }; |
| 82 | + |
| 83 | + processArgs = attrs: |
| 84 | + let |
| 85 | + attrsWithCompileFlags = applyFlags attrs "NIX_CFLAGS_COMPILE" extraCompile; |
| 86 | + in |
| 87 | + applyFlags attrsWithCompileFlags "NIX_CFLAGS_LINK" extraLink; |
| 88 | + in |
| 89 | + if builtins.isFunction args then |
| 90 | + mkDerivationSuper (self: processArgs (args self)) |
| 91 | + else |
| 92 | + mkDerivationSuper (processArgs args); |
| 93 | + }); |
| 94 | + in |
| 95 | + customStdenv pkgs.stdenv; |
45 | 96 |
|
46 | 97 | # RUSTFLAGS = "-C target-cpu=znver3 "; |
47 | 98 | # permittedInsecurePackages = [ "nix-2.15.3" ]; |
|
0 commit comments