Skip to content

Commit ab6f317

Browse files
committed
direnv: pass flags to devenv
1 parent 4e904c0 commit ab6f317

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

devenv/direnvrc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,17 @@ _devenv_watches() {
102102
use_devenv() {
103103
_nix_direnv_preflight
104104

105+
# First parameter is the flake expression, defaults to .
105106
flake_expr="${1:-.}"
107+
shift 2>/dev/null || true
108+
109+
# Remaining parameters are passed as flags to devenv
110+
local devenv_cmd=("${DEVENV_BIN}")
111+
# Add all arguments passed to use_devenv after the flake_expr
112+
if (( $# > 0 )); then
113+
devenv_cmd+=("$@")
114+
fi
115+
106116
flake_dir="${flake_expr%#*}"
107117
env_deps_path="$flake_dir/.devenv/input-paths.txt"
108118

@@ -113,8 +123,8 @@ use_devenv() {
113123
default_watches+=("$flake_dir/devenv.nix" "$flake_dir/devenv.lock" "$flake_dir/devenv.yaml" "$flake_dir/devenv.local.nix")
114124

115125
if [[ -f "$flake_dir/devenv.yaml" ]]; then
116-
if ! devenv assemble; then
117-
log_error "$(devenv version) failed to parse devenv.yaml, make sure to use version 0.6 or newer and fix the errors above."
126+
if ! "${devenv_cmd[@]}" assemble; then
127+
log_error "$("${DEVENV_BIN}" version) failed to parse devenv.yaml, make sure to use version 0.6 or newer and fix the errors above."
118128
exit 0
119129
fi
120130
fi
@@ -129,9 +139,10 @@ use_devenv() {
129139
_devenv_watches "$env_deps_path" env_watches
130140
watch_file "${env_watches[@]}"
131141

132-
# Build the environment
142+
# Build the environment with all flags passed through
133143
local env
134-
if ! env=$("${DEVENV_BIN}" print-dev-env); then
144+
local print_cmd=("${devenv_cmd[@]}" "print-dev-env")
145+
if ! env=$("${print_cmd[@]}"); then
135146
log_error "failed to build the devenv environment. devenv.nix may contain errors. see above."
136147
exit 0
137148
fi

devenv/init/.envrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ export DIRENV_WARN_TIMEOUT=20s
22

33
eval "$(devenv direnvrc)"
44

5+
# The use_devenv function supports passing flags to the devenv command
6+
# For example: use devenv --impure --option services.postgres.enable:bool true
57
use devenv

docs/automatic-shell-activation.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ To enable automatic shell activation, create an `.envrc` file in your project di
1616
``` bash title=".envrc"
1717
eval "$(devenv direnvrc)"
1818

19+
# You can pass flags to the devenv command
20+
# For example: use devenv --impure --option services.postgres.enable:bool true
1921
use devenv
2022
```
2123

@@ -52,6 +54,15 @@ Entering shell ...
5254
(devenv) $
5355
```
5456

57+
## Passing flags to devenv
58+
59+
You can pass command-line options directly to devenv by adding them after the `use devenv` command in your `.envrc` file:
60+
61+
```bash
62+
# Example: override configuration options
63+
use devenv --option services.postgres.enable:bool true
64+
```
65+
5566
## Customizing PS1
5667

5768
If you'd like to use direnv and have your prompt be aware of it,

0 commit comments

Comments
 (0)