From 02e7f40ce3200bda666d7271d3e668b2ca8a969c Mon Sep 17 00:00:00 2001 From: Sander Date: Fri, 8 May 2026 20:45:11 +0200 Subject: [PATCH 1/4] nix: export shell hooks under `$out/share/devenv/shell-integration//` --- nix/workspace.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nix/workspace.nix b/nix/workspace.nix index dfaf75a53..af59f9cbb 100644 --- a/nix/workspace.nix +++ b/nix/workspace.nix @@ -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// + # 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"; From 51ab0726f66f5b4b0a495bdf5f3a0b851317a097 Mon Sep 17 00:00:00 2001 From: Sander Date: Fri, 8 May 2026 21:06:59 +0200 Subject: [PATCH 2/4] nix: export NixOS and home-manager modules Use these modules to configure shells with auto-loading devenv hooks. --- flake.nix | 3 +++ nix/home-manager-module.nix | 47 +++++++++++++++++++++++++++++++++++++ nix/nixos-module.nix | 40 +++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 nix/home-manager-module.nix create mode 100644 nix/nixos-module.nix diff --git a/flake.nix b/flake.nix index f81ea9751..51fd120a0 100644 --- a/flake.nix +++ b/flake.nix @@ -168,6 +168,9 @@ default = self.templates.flake; }; + nixosModules.default = import ./nix/nixos-module.nix; + homeManagerModules.default = import ./nix/home-manager-module.nix; + flakeModule = self.flakeModules.default; # Backwards compatibility flakeModules = { default = import ./flake-module.nix self; diff --git a/nix/home-manager-module.nix b/nix/home-manager-module.nix new file mode 100644 index 000000000..9c538d64c --- /dev/null +++ b/nix/home-manager-module.nix @@ -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"}" + ''; + }) + ]); +} diff --git a/nix/nixos-module.nix b/nix/nixos-module.nix new file mode 100644 index 000000000..cf0338833 --- /dev/null +++ b/nix/nixos-module.nix @@ -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"}" + ''; + }) + ]); +} From 6021b3a6b1357744bf67db76e86010f5465b0810 Mon Sep 17 00:00:00 2001 From: Sander Date: Fri, 8 May 2026 21:13:35 +0200 Subject: [PATCH 3/4] docs: document NixOS and home-manager modules --- CHANGELOG.md | 3 ++- docs/src/auto-activation.md | 47 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c213a69f4..54108b37e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` 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//hook.` 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. diff --git a/docs/src/auto-activation.md b/docs/src/auto-activation.md index 4f3284cf1..e35816667 100644 --- a/docs/src/auto-activation.md +++ b/docs/src/auto-activation.md @@ -33,6 +33,53 @@ Add one line to your shell configuration file: source ~/.cache/devenv/hook.nu ``` +## Setup via the NixOS or home-manager module + +!!! tip "New in version 2.2" + +[NixOS](https://nixos.org/) 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; + } + ``` + +=== "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//hook.` 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. From 2dc335f50bf0568e43aab0b2dff22fd9e60a00bf Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 11 May 2026 15:00:45 +0200 Subject: [PATCH 4/4] nix: add a nix-darwin module for auto-activation --- CHANGELOG.md | 2 +- docs/src/auto-activation.md | 15 ++++++++++++-- flake.nix | 1 + nix/nix-darwin-module.nix | 40 +++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 nix/nix-darwin-module.nix diff --git a/CHANGELOG.md b/CHANGELOG.md index 54108b37e..b70264359 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ ### Improvements -- Added `nixosModules.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//hook.` so they can be sourced directly. +- 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//hook.` 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. diff --git a/docs/src/auto-activation.md b/docs/src/auto-activation.md index e35816667..2d6cc51ff 100644 --- a/docs/src/auto-activation.md +++ b/docs/src/auto-activation.md @@ -33,11 +33,11 @@ Add one line to your shell configuration file: source ~/.cache/devenv/hook.nu ``` -## Setup via the NixOS or home-manager module +## Setup via the NixOS, nix-darwin, or home-manager module !!! tip "New in version 2.2" -[NixOS](https://nixos.org/) 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. +[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: @@ -58,6 +58,17 @@ Add devenv as a flake input: } ``` +=== "nix-darwin" + + ```nix title="configuration.nix" + { inputs, ... }: + { + imports = [ inputs.devenv.darwinModules.default ]; + + programs.devenv.enable = true; + } + ``` + === "home-manager" ```nix title="home.nix" diff --git a/flake.nix b/flake.nix index 51fd120a0..349716d92 100644 --- a/flake.nix +++ b/flake.nix @@ -169,6 +169,7 @@ }; 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 diff --git a/nix/nix-darwin-module.nix b/nix/nix-darwin-module.nix new file mode 100644 index 000000000..cf0338833 --- /dev/null +++ b/nix/nix-darwin-module.nix @@ -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"}" + ''; + }) + ]); +}