Skip to content
Open
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

### Improvements

`devenv shell` now registers zsh completions from packages in the devenv profile. A generated `.zshenv` prepends `$DEVENV_PROFILE/share/zsh/site-functions` to `fpath` before `/etc/zshrc` runs, so the system `compinit` picks up the new directory.
- Added `nixosModules.default`, `darwinModules.default`, and `homeManagerModules.default` flake outputs that expose `programs.devenv.enable` and per-shell integration toggles. The package now also installs hook scripts under `$out/share/devenv/shell-integration/<shell>/hook.<ext>` so they can be sourced directly.
- `devenv shell` now registers zsh completions from packages in the devenv profile. A generated `.zshenv` prepends `$DEVENV_PROFILE/share/zsh/site-functions` to `fpath` before `/etc/zshrc` runs, so the system `compinit` picks up the new directory.
- Bumped `secretspec` to `v0.10.1`. The new `bws` (Bitwarden Secrets Manager) feature is not enabled because its transitive `bitwarden` crate conflicts with `sqlx` 0.8 on `libsqlite3-sys` and pins `typenum` to 1.18.
- Bumped `iocraft` to `0.8.2` and switched the `[patch.crates-io]` entry from the `cachix/iocraft` fork to upstream `ccbrown/iocraft` `main`, now that the row-level diff and stderr rendering patches are merged upstream.

Expand Down
58 changes: 58 additions & 0 deletions docs/src/auto-activation.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,64 @@ Add one line to your shell configuration file:
source ~/.cache/devenv/hook.nu
```

## Setup via the NixOS, nix-darwin, or home-manager module

!!! tip "New in version 2.2"

[NixOS](https://nixos.org/), [nix-darwin](https://github.com/nix-darwin/nix-darwin), and [home-manager](https://github.com/nix-community/home-manager) users can import the flake modules that devenv ships, which install the package and source the shell hook for every shell you have enabled — no rc-file edits required.

Add devenv as a flake input:

```nix title="flake.nix"
{
inputs.devenv.url = "github:cachix/devenv";
}
```

=== "NixOS"

```nix title="configuration.nix"
{ inputs, ... }:
{
imports = [ inputs.devenv.nixosModules.default ];

programs.devenv.enable = true;
}
```

=== "nix-darwin"

```nix title="configuration.nix"
{ inputs, ... }:
{
imports = [ inputs.devenv.darwinModules.default ];

programs.devenv.enable = true;
}
```

=== "home-manager"

```nix title="home.nix"
{ inputs, ... }:
{
imports = [ inputs.devenv.homeManagerModules.default ];

programs.devenv.enable = true;
}
```

By default, every supported shell that you have enabled also gets the hook sourced. Disable an individual integration with:

```nix
programs.devenv.enableBashIntegration = false;
programs.devenv.enableZshIntegration = false;
programs.devenv.enableFishIntegration = false;
programs.devenv.enableNushellIntegration = false; # home-manager only
```

The exported hook scripts are also available directly under `${pkgs.devenv}/share/devenv/shell-integration/<shell>/hook.<ext>` if you want to wire them up by hand.

## Trusting a project

Before a project can auto activate, you need to explicitly trust it. This is a security measure that prevents untrusted projects from modifying your shell.
Expand Down
4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@
default = self.templates.flake;
};

nixosModules.default = import ./nix/nixos-module.nix;
darwinModules.default = import ./nix/nix-darwin-module.nix;
homeManagerModules.default = import ./nix/home-manager-module.nix;

flakeModule = self.flakeModules.default; # Backwards compatibility
flakeModules = {
default = import ./flake-module.nix self;
Expand Down
47 changes: 47 additions & 0 deletions nix/home-manager-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{ config, lib, pkgs, ... }:
let
cfg = config.programs.devenv;
hookPath = shell: ext: "${cfg.package}/share/devenv/shell-integration/${shell}/hook.${ext}";
in
{
options.programs.devenv = {
enable = lib.mkEnableOption "devenv, fast declarative reproducible developer environments";

package = lib.mkPackageOption pkgs "devenv" { };

enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; };
enableZshIntegration = lib.hm.shell.mkZshIntegrationOption { inherit config; };
enableFishIntegration = lib.hm.shell.mkFishIntegrationOption { inherit config; };
enableNushellIntegration = lib.hm.shell.mkNushellIntegrationOption { inherit config; };
};

config = lib.mkIf cfg.enable (lib.mkMerge [
{
home.packages = [ cfg.package ];
}

(lib.mkIf cfg.enableBashIntegration {
programs.bash.initExtra = ''
source "${hookPath "bash" "sh"}"
'';
})

(lib.mkIf cfg.enableZshIntegration {
programs.zsh.initContent = ''
source "${hookPath "zsh" "zsh"}"
'';
})

(lib.mkIf cfg.enableFishIntegration {
programs.fish.interactiveShellInit = ''
source "${hookPath "fish" "fish"}"
'';
})

(lib.mkIf cfg.enableNushellIntegration {
programs.nushell.extraConfig = ''
source "${hookPath "nu" "nu"}"
'';
})
]);
}
40 changes: 40 additions & 0 deletions nix/nix-darwin-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{ config, lib, pkgs, ... }:
let
cfg = config.programs.devenv;
hookPath = shell: ext: "${cfg.package}/share/devenv/shell-integration/${shell}/hook.${ext}";
in
{
options.programs.devenv = {
enable = lib.mkEnableOption "devenv, fast declarative reproducible developer environments";

package = lib.mkPackageOption pkgs "devenv" { };

enableBashIntegration = lib.mkEnableOption "Bash integration" // { default = true; };
enableZshIntegration = lib.mkEnableOption "Zsh integration" // { default = true; };
enableFishIntegration = lib.mkEnableOption "Fish integration" // { default = true; };
};

config = lib.mkIf cfg.enable (lib.mkMerge [
{
environment.systemPackages = [ cfg.package ];
}

(lib.mkIf cfg.enableBashIntegration {
programs.bash.interactiveShellInit = ''
source "${hookPath "bash" "sh"}"
'';
})

(lib.mkIf cfg.enableZshIntegration {
programs.zsh.interactiveShellInit = ''
source "${hookPath "zsh" "zsh"}"
'';
})

(lib.mkIf cfg.enableFishIntegration {
programs.fish.interactiveShellInit = ''
source "${hookPath "fish" "fish"}"
'';
})
]);
}
40 changes: 40 additions & 0 deletions nix/nixos-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{ config, lib, pkgs, ... }:
let
cfg = config.programs.devenv;
hookPath = shell: ext: "${cfg.package}/share/devenv/shell-integration/${shell}/hook.${ext}";
in
{
options.programs.devenv = {
enable = lib.mkEnableOption "devenv, fast declarative reproducible developer environments";

package = lib.mkPackageOption pkgs "devenv" { };

enableBashIntegration = lib.mkEnableOption "Bash integration" // { default = true; };
enableZshIntegration = lib.mkEnableOption "Zsh integration" // { default = true; };
enableFishIntegration = lib.mkEnableOption "Fish integration" // { default = true; };
};

config = lib.mkIf cfg.enable (lib.mkMerge [
{
environment.systemPackages = [ cfg.package ];
}

(lib.mkIf cfg.enableBashIntegration {
programs.bash.interactiveShellInit = ''
source "${hookPath "bash" "sh"}"
'';
})

(lib.mkIf cfg.enableZshIntegration {
programs.zsh.interactiveShellInit = ''
source "${hookPath "zsh" "zsh"}"
'';
})

(lib.mkIf cfg.enableFishIntegration {
programs.fish.interactiveShellInit = ''
source "${hookPath "fish" "fish"}"
'';
})
]);
}
9 changes: 9 additions & 0 deletions nix/workspace.nix
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ let
--bash $compdir/devenv.bash \
--fish $compdir/devenv.fish \
--zsh $compdir/_devenv

# Export shell hook scripts under $out/share/devenv/shell-integration/<shell>/
# for users (or home-manager modules) to source.
integration=$out/share/devenv/shell-integration
mkdir -p $integration/bash $integration/zsh $integration/fish $integration/nu
$out/bin/devenv hook bash > $integration/bash/hook.sh
$out/bin/devenv hook zsh > $integration/zsh/hook.zsh
$out/bin/devenv hook fish > $integration/fish/hook.fish
$out/bin/devenv hook nu > $integration/nu/hook.nu
'';

meta.mainProgram = "devenv";
Expand Down
Loading