|
69 | 69 | stdenv = lib.mkOption {
|
70 | 70 | type = types.package;
|
71 | 71 | description = "The stdenv to use for the developer environment.";
|
72 |
| - default = pkgs.stdenv; |
| 72 | + default = |
| 73 | + if pkgs.stdenv.isDarwin |
| 74 | + then |
| 75 | + pkgs.stdenv.override |
| 76 | + (prev: { |
| 77 | + # Remove the default apple-sdk on macOS. |
| 78 | + # Prefer to expose the system SDK, or let the user specify the SDK in `packages`. |
| 79 | + extraBuildInputs = |
| 80 | + builtins.filter (x: !lib.hasPrefix "apple-sdk" x.pname) prev.extraBuildInputs; |
| 81 | + }) |
| 82 | + else pkgs.stdenv; |
73 | 83 | defaultText = lib.literalExpression "pkgs.stdenv";
|
74 | 84 | };
|
75 | 85 |
|
|
297 | 307 | ln -snf ${lib.escapeShellArg config.devenv.runtime} ${lib.escapeShellArg config.devenv.dotfile}/run
|
298 | 308 | '';
|
299 | 309 |
|
300 |
| - shell = performAssertions ( |
301 |
| - (pkgs.mkShell.override { stdenv = config.stdenv; }) ({ |
302 |
| - hardeningDisable = config.hardeningDisable; |
303 |
| - name = "devenv-shell"; |
304 |
| - packages = config.packages; |
305 |
| - shellHook = '' |
306 |
| - ${lib.optionalString config.devenv.debug "set -x"} |
307 |
| - ${config.enterShell} |
308 |
| - ''; |
309 |
| - } // config.env) |
310 |
| - ); |
| 310 | + shell = |
| 311 | + let |
| 312 | + # `mkShell` merges `packages` into `nativeBuildInputs`. |
| 313 | + # This distinction is generally not important for devShells, except when it comes to setup hooks and their run order. |
| 314 | + # On macOS, the default apple-sdk is added the stdenv via `extraBuildInputs`. |
| 315 | + # If we don't remove it from stdenv, then it's setup hooks will clobber any SDK added to `packages`. |
| 316 | + isAppleSDK = pkg: builtins.match ".*apple-sdk.*" (pkg.pname or "") != null; |
| 317 | + partitionedPkgs = builtins.partition isAppleSDK config.packages; |
| 318 | + buildInputs = partitionedPkgs.right; |
| 319 | + nativeBuildInputs = partitionedPkgs.wrong; |
| 320 | + in |
| 321 | + performAssertions ( |
| 322 | + (pkgs.mkShell.override { stdenv = config.stdenv; }) ({ |
| 323 | + name = "devenv-shell"; |
| 324 | + hardeningDisable = config.hardeningDisable; |
| 325 | + inherit buildInputs nativeBuildInputs; |
| 326 | + shellHook = '' |
| 327 | + ${lib.optionalString config.devenv.debug "set -x"} |
| 328 | + ${config.enterShell} |
| 329 | + ''; |
| 330 | + } // config.env) |
| 331 | + ); |
311 | 332 |
|
312 | 333 | infoSections."env" = lib.mapAttrsToList (name: value: "${name}: ${toString value}") config.env;
|
313 | 334 | infoSections."packages" = builtins.map (package: package.name) (builtins.filter (package: !(builtins.elem package.name (builtins.attrNames config.scripts))) config.packages);
|
|
0 commit comments