diff --git a/README.md b/README.md index d3d6cd91..4cd00527 100644 --- a/README.md +++ b/README.md @@ -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: ``` @@ -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 @@ -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 diff --git a/devshell.toml b/devshell.toml index 9b32d56e..22626880 100644 --- a/devshell.toml +++ b/devshell.toml @@ -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" diff --git a/modules/back-compat.nix b/modules/back-compat.nix index e9eeb99d..6413aef6 100644 --- a/modules/back-compat.nix +++ b/modules/back-compat.nix @@ -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; } diff --git a/modules/devshell.nix b/modules/devshell.nix index 7e4c5545..d4e98dda 100644 --- a/modules/devshell.nix +++ b/modules/devshell.nix @@ -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 = { @@ -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; @@ -331,6 +348,8 @@ in config.devshell = { package = devshell_dir; + packages = foldl' (sum: drv: sum ++ (inputsOf drv)) [ ] cfg.packagesFrom; + startup = { motd = noDepEntry '' __devshell-motd() { diff --git a/overlay.nix b/overlay.nix index 0e054241..2d195552 100644 --- a/overlay.nix +++ b/overlay.nix @@ -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; };