Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: devShell interface #206728

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkgs/stdenv/adapters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkgs/stdenv/cross/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ lib
, localSystem, crossSystem, config, overlays, crossOverlays ? []
, defaultDevShell
}:

let
Expand All @@ -11,6 +12,8 @@ let

# Ignore custom stdenvs when cross compiling for compatability
config = builtins.removeAttrs config [ "replaceStdenv" ];

inherit defaultDevShell;
};

in lib.init bootStages ++ [
Expand Down
5 changes: 3 additions & 2 deletions pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -668,7 +669,7 @@ rec {
import ../generic rec {
name = "stdenv-darwin";

inherit config;
inherit config defaultDevShell;
inherit (pkgs.stdenv) fetchurlBoot;

buildPlatform = localSystem;
Expand Down
1 change: 1 addition & 0 deletions pkgs/stdenv/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
lib
# Args to pass on to the pkgset builder, too
, localSystem, crossSystem, config, overlays, crossOverlays ? []
, defaultDevShell
} @ args:

let
Expand Down
30 changes: 30 additions & 0 deletions pkgs/stdenv/devShell.nix
Original file line number Diff line number Diff line change
@@ -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}
Comment on lines +11 to +12
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See streamNixShellImage for how to do this kind of thing.


'').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;
})
5 changes: 4 additions & 1 deletion pkgs/stdenv/generic/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions pkgs/stdenv/generic/make-derivation.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{ lib, config }:
{ lib,
config,
# Function to construct the default devShell attribute; when not set via passthru.
defaultDevShell ? _: null,
}:

stdenv:

Expand Down Expand Up @@ -473,6 +477,8 @@ else let
else true);
};

drv = derivation derivationArg;

in

lib.extendDerivation
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions pkgs/stdenv/linux/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -461,6 +462,8 @@ in
inherit (prevStage) binutils binutils-unwrapped;
gcc = cc;
};

inherit defaultDevShell;
};
})

Expand Down
4 changes: 4 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };
Expand Down
1 change: 1 addition & 0 deletions pkgs/top-level/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ in let

stages = stdenvStages {
inherit lib localSystem crossSystem config overlays crossOverlays;
inherit (pkgs) defaultDevShell;
};

pkgs = boot stages;
Expand Down