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

enable packagesFrom #261

Merged
merged 3 commits into from
Jun 13, 2023
Merged
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
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ new environment variables, which then need to be unset. The `stdenv` itself
contains either GCC or Clang which makes it hard to select a specific C
compiler.

This is why `mkDevShell` builds its environment from a `builtins.derivation`.
This is why `mkShell` builds its environment from a `builtins.derivation`.

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

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

```
### 🔨 Welcome to mkDevShell ####
🔨 Welcome to devshell

# Commands

Expand All @@ -90,13 +89,12 @@ handle 80% of the use-cases and falling back on Nix is always possible.
Life is not complete otherwise. Huhu.

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

### Capture development dependencies in CI

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

```sh
Expand Down
5 changes: 5 additions & 0 deletions devshell.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ packages = [
"hyperfine",
]

# Expose all the dependencies from a package to the environment.
packagesFrom = [
"direnv"
]

# Declare commands that are available in the environment.
[[commands]]
help = "prints hello"
Expand Down
7 changes: 7 additions & 0 deletions modules/back-compat.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@ with lib;
type = types.listOf strOrPackage;
default = [ ];
};

packagesFrom = mkOption {
internal = true;
type = types.listOf strOrPackage;
default = [ ];
};
};

# Copy the values over to the devshell module
config.devshell =
{
packages = config.packages;
packagesFrom = config.packagesFrom;
startup.bash_extra = noDepEntry config.bash.extra;
interactive.bash_interactive = noDepEntry config.bash.interactive;
}
Expand Down
19 changes: 19 additions & 0 deletions modules/devshell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ let
'';
};

# Returns a list of all the input derivation ... for a derivation.
inputsOf = drv:
(drv.buildInputs or [ ]) ++
(drv.nativeBuildInputs or [ ]) ++
(drv.propagatedBuildInputs or [ ]) ++
(drv.propagatedNativeBuildInputs or [ ])
;

in
{
options.devshell = {
Expand Down Expand Up @@ -291,6 +299,15 @@ in
'';
};

packagesFrom = mkOption {
type = types.listOf strOrPackage;
default = [ ];
description = ''
Add all the build dependencies from the listed packages to the
environment.
'';
};

shell = mkOption {
internal = true;
type = types.package;
Expand Down Expand Up @@ -331,6 +348,8 @@ in
config.devshell = {
package = devshell_dir;

packages = foldl' (sum: drv: sum ++ (inputsOf drv)) [ ] cfg.packagesFrom;

startup = {
motd = noDepEntry ''
__devshell-motd() {
Expand Down
2 changes: 1 addition & 1 deletion overlay.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Import this overlay in your project to add devshell and mkDevShell
# Import this overlay in your project to add devshell
final: prev:
{
devshell = import ./. { nixpkgs = final; };
Expand Down