diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 85bd8d2087f66..29eb73f55f5f6 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -6,7 +6,7 @@ let # N.B. Keep in sync with default arg for stdenv/generic. - defaultMkDerivationFromStdenv = import ./generic/make-derivation.nix { inherit lib config; }; + defaultMkDerivationFromStdenv = import ./generic/make-derivation.nix { inherit lib config; inherit (pkgs) defaultDevShell; }; # Low level function to help with overriding `mkDerivationFromStdenv`. One # gives it the old stdenv arguments and a "continuation" function, and diff --git a/pkgs/stdenv/cross/default.nix b/pkgs/stdenv/cross/default.nix index bf410ec0a6841..2f1c909c94e28 100644 --- a/pkgs/stdenv/cross/default.nix +++ b/pkgs/stdenv/cross/default.nix @@ -1,5 +1,6 @@ { lib , localSystem, crossSystem, config, overlays, crossOverlays ? [] +, defaultDevShell }: let @@ -11,6 +12,8 @@ let # Ignore custom stdenvs when cross compiling for compatability config = builtins.removeAttrs config [ "replaceStdenv" ]; + + inherit defaultDevShell; }; in lib.init bootStages ++ [ diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index 9a7cd9aa9dee5..a9f2c420d1b77 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -34,6 +34,7 @@ cpio = fetch { file = "cpio"; sha256 = "sha256-SWkwvLaFyV44kLKL2nx720SvcL4ej/p2V/bX3uqAGO0="; }; tarball = fetch { file = "bootstrap-tools.cpio.bz2"; sha256 = "sha256-kRC/bhCmlD4L7KAvJQgcukk7AinkMz4IwmG1rqlh5tA="; executable = false; }; } +, defaultDevShell }: assert crossSystem == localSystem; @@ -149,7 +150,7 @@ rec { thisStdenv = import ../generic { name = "${name}-stdenv-darwin"; - inherit config shell extraBuildInputs; + inherit config shell extraBuildInputs defaultDevShell; extraNativeBuildInputs = extraNativeBuildInputs ++ lib.optionals doUpdateAutoTools [ last.pkgs.updateAutotoolsGnuConfigScriptsHook @@ -668,7 +669,7 @@ rec { import ../generic rec { name = "stdenv-darwin"; - inherit config; + inherit config defaultDevShell; inherit (pkgs.stdenv) fetchurlBoot; buildPlatform = localSystem; diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix index 7a2ad665e09d7..521ea9f585c1d 100644 --- a/pkgs/stdenv/default.nix +++ b/pkgs/stdenv/default.nix @@ -8,6 +8,7 @@ lib # Args to pass on to the pkgset builder, too , localSystem, crossSystem, config, overlays, crossOverlays ? [] +, defaultDevShell } @ args: let diff --git a/pkgs/stdenv/devShell.nix b/pkgs/stdenv/devShell.nix new file mode 100644 index 0000000000000..4cbaf1751253e --- /dev/null +++ b/pkgs/stdenv/devShell.nix @@ -0,0 +1,30 @@ +{ pkgs }: +{ drv, ... }: + +# stdenvDevShell only supports simple derivations, not generalized packages or anything else. +assert drv?drvPath && drv.type or null == "derivation"; + +# TODO: fork and improve nix-shell logic +(pkgs.buildPackages.writeScriptBin "devShell" '' + #!${pkgs.buildPackages.runtimeShell} + + # TODO replicate in bash + exec ${pkgs.buildPackages.nix}/bin/nix-shell ${builtins.unsafeDiscardOutputDependency drv.drvPath} + +'').overrideAttrs (prevAttrs: { + buildCommand = '' + # Write the bin/devShell command + ${prevAttrs.buildCommand} + mkdir -p $out + + # environment.sh exposes the environment, but no bash functions + cp $inputDerivation $out/environment.sh + + # TODO implement this and use it in the devShell command + # should this have a different name? + # setup.sh loads the derivation-like environment variables and stdenv/setup.sh + echo '# TODO' >$out/setup.sh + ''; + # TODO not sure if these must be equal; may want to reimplement this, maybe? + inherit (drv) inputDerivation; +}) diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index 81255726284b5..0ff8c8eac7cc8 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -52,7 +52,10 @@ argsStdenv@{ name ? "stdenv", preHook ? "", initialPath , # The implementation of `mkDerivation`, parameterized with the final stdenv so we can tie the knot. # This is convient to have as a parameter so the stdenv "adapters" work better - mkDerivationFromStdenv ? import ./make-derivation.nix { inherit lib config; } + mkDerivationFromStdenv ? import ./make-derivation.nix { inherit lib config defaultDevShell; } + +, # See ./make-derivation.nix + defaultDevShell ? _: null }: let diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index 510537aac9f39..b2fa9c6388a78 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -1,4 +1,8 @@ -{ lib, config }: +{ lib, + config, + # Function to construct the default devShell attribute; when not set via passthru. + defaultDevShell ? _: null, +}: stdenv: @@ -473,6 +477,8 @@ else let else true); }; + drv = derivation derivationArg; + in lib.extendDerivation @@ -503,13 +509,18 @@ lib.extendDerivation args = [ "-c" "export > $out" ]; }); + devShell = defaultDevShell { + # TODO bring `finalPackage` into scope here. + drv = overrideAttrs (o: {}); + }; + inherit meta passthru overrideAttrs; } // # Pass through extra attributes that are not inputs, but # should be made available to Nix expressions using the # derivation (e.g., in assertions). passthru) - (derivation derivationArg); + drv; in fnOrAttrs: diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index dbaff342fb1af..9b6153a2c04a9 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -40,6 +40,7 @@ files = archLookupTable.${localSystem.system} or (if getCompatibleTools != null then getCompatibleTools else (abort "unsupported platform for the pure Linux stdenv")); in files +, defaultDevShell }: assert crossSystem == localSystem; @@ -461,6 +462,8 @@ in inherit (prevStage) binutils binutils-unwrapped; gcc = cc; }; + + inherit defaultDevShell; }; }) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 4b906f8c5f42f..76cd2cf98112d 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -112,6 +112,10 @@ with pkgs; tests = callPackages ../test {}; + stdenvDevShell = import ../stdenv/devShell.nix { inherit pkgs; }; + + defaultDevShell = stdenvDevShell; + ### Nixpkgs maintainer tools nix-generate-from-cpan = callPackage ../../maintainers/scripts/nix-generate-from-cpan.nix { }; diff --git a/pkgs/top-level/default.nix b/pkgs/top-level/default.nix index b32aabc3a1fdf..a1e8378d8168c 100644 --- a/pkgs/top-level/default.nix +++ b/pkgs/top-level/default.nix @@ -124,6 +124,7 @@ in let stages = stdenvStages { inherit lib localSystem crossSystem config overlays crossOverlays; + inherit (pkgs) defaultDevShell; }; pkgs = boot stages;