Skip to content

Commit 268a3d8

Browse files
bors[bot]zimbatmdeemp
authored
Merge #261
261: enable packagesFrom r=zimbatm a=deemp Co-authored-by: zimbatm <[email protected]> Co-authored-by: Danila Danko <[email protected]>
2 parents 6b2554d + 5326be2 commit 268a3d8

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ new environment variables, which then need to be unset. The `stdenv` itself
3434
contains either GCC or Clang which makes it hard to select a specific C
3535
compiler.
3636

37-
This is why `mkDevShell` builds its environment from a `builtins.derivation`.
37+
This is why `mkShell` builds its environment from a `builtins.derivation`.
3838

3939
direnv loads will change from:
4040
```
@@ -65,11 +65,10 @@ those are useful yet:
6565
When entering a random project, it's useful to get a quick view of what
6666
commands are available.
6767

68-
When running `nix-shell` or `nix develop`, `mkDevShell` prints a welcome
69-
message:
68+
When running `nix-shell` or `nix develop`, `mkShell` prints a welcome message:
7069

7170
```
72-
### 🔨 Welcome to mkDevShell ####
71+
🔨 Welcome to devshell
7372
7473
# Commands
7574
@@ -90,13 +89,12 @@ handle 80% of the use-cases and falling back on Nix is always possible.
9089
Life is not complete otherwise. Huhu.
9190

9291
Packages that contain bash completions will automatically be loaded by
93-
`mkDevShell` in `nix-shell` or `nix develop` modes.
92+
`mkShell` in `nix-shell` or `nix develop` modes.
9493

9594
### Capture development dependencies in CI
9695

9796
With a CI + Binary cache setup, one often wants to be able to capture all the
98-
build inputs of a `shell.nix`. Before, `pkgs.mkShell` would even refuse to
99-
build! (my fault really). With `pkgs.mkDevShell`, capturing all of the
97+
build inputs of a `shell.nix`. With `mkShell` capturing all of the
10098
development dependencies is as easy as:
10199

102100
```sh

devshell.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ packages = [
2525
"hyperfine",
2626
]
2727

28+
# Expose all the dependencies from a package to the environment.
29+
packagesFrom = [
30+
"direnv"
31+
]
32+
2833
# Declare commands that are available in the environment.
2934
[[commands]]
3035
help = "prints hello"

modules/back-compat.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,19 @@ with lib;
3737
type = types.listOf strOrPackage;
3838
default = [ ];
3939
};
40+
41+
packagesFrom = mkOption {
42+
internal = true;
43+
type = types.listOf strOrPackage;
44+
default = [ ];
45+
};
4046
};
4147

4248
# Copy the values over to the devshell module
4349
config.devshell =
4450
{
4551
packages = config.packages;
52+
packagesFrom = config.packagesFrom;
4653
startup.bash_extra = noDepEntry config.bash.extra;
4754
interactive.bash_interactive = noDepEntry config.bash.interactive;
4855
}

modules/devshell.nix

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ let
196196
'';
197197
};
198198

199+
# Returns a list of all the input derivation ... for a derivation.
200+
inputsOf = drv:
201+
(drv.buildInputs or [ ]) ++
202+
(drv.nativeBuildInputs or [ ]) ++
203+
(drv.propagatedBuildInputs or [ ]) ++
204+
(drv.propagatedNativeBuildInputs or [ ])
205+
;
206+
199207
in
200208
{
201209
options.devshell = {
@@ -291,6 +299,15 @@ in
291299
'';
292300
};
293301

302+
packagesFrom = mkOption {
303+
type = types.listOf strOrPackage;
304+
default = [ ];
305+
description = ''
306+
Add all the build dependencies from the listed packages to the
307+
environment.
308+
'';
309+
};
310+
294311
shell = mkOption {
295312
internal = true;
296313
type = types.package;
@@ -331,6 +348,8 @@ in
331348
config.devshell = {
332349
package = devshell_dir;
333350

351+
packages = foldl' (sum: drv: sum ++ (inputsOf drv)) [ ] cfg.packagesFrom;
352+
334353
startup = {
335354
motd = noDepEntry ''
336355
__devshell-motd() {

overlay.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Import this overlay in your project to add devshell and mkDevShell
1+
# Import this overlay in your project to add devshell
22
final: prev:
33
{
44
devshell = import ./. { nixpkgs = final; };

0 commit comments

Comments
 (0)