Skip to content
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
27 changes: 17 additions & 10 deletions devenv/direnvrc
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,25 @@ _devenv_watches() {
use_devenv() {
_nix_direnv_preflight

flake_expr="${1:-.}"
flake_dir="${flake_expr%#*}"
env_deps_path="$flake_dir/.devenv/input-paths.txt"
# Remaining parameters are passed as flags to devenv
local devenv_cmd=("${DEVENV_BIN}")
# Add all arguments passed to use_devenv
if (( $# > 0 )); then
devenv_cmd+=("$@")
fi

devenv_dir=.
env_deps_path="$devenv_dir/.devenv/input-paths.txt"

local default_watches
default_watches=(".envrc" "$HOME/.direnvrc" "$HOME/.config/direnv/direnvrc")

if [[ -d "$flake_dir" ]]; then
default_watches+=("$flake_dir/devenv.nix" "$flake_dir/devenv.lock" "$flake_dir/devenv.yaml" "$flake_dir/devenv.local.nix")
if [[ -d "$devenv_dir" ]]; then
default_watches+=("$devenv_dir/devenv.nix" "$devenv_dir/devenv.lock" "$devenv_dir/devenv.yaml" "$devenv_dir/devenv.local.nix")

if [[ -f "$flake_dir/devenv.yaml" ]]; then
if ! devenv assemble; then
log_error "$(devenv version) failed to parse devenv.yaml, make sure to use version 0.6 or newer and fix the errors above."
if [[ -f "$devenv_dir/devenv.yaml" ]]; then
if ! "${devenv_cmd[@]}" assemble; then
log_error "$("${DEVENV_BIN}" version) failed to parse devenv.yaml, make sure to use version 0.6 or newer and fix the errors above."
exit 0
fi
fi
Expand All @@ -129,9 +135,10 @@ use_devenv() {
_devenv_watches "$env_deps_path" env_watches
watch_file "${env_watches[@]}"

# Build the environment
# Build the environment with all flags passed through
local env
if ! env=$("${DEVENV_BIN}" print-dev-env); then
local print_cmd=("${devenv_cmd[@]}" "print-dev-env")
if ! env=$("${print_cmd[@]}"); then
log_error "failed to build the devenv environment. devenv.nix may contain errors. see above."
exit 0
fi
Expand Down
2 changes: 2 additions & 0 deletions devenv/init/.envrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ export DIRENV_WARN_TIMEOUT=20s

eval "$(devenv direnvrc)"

# The use_devenv function supports passing flags to the devenv command
# For example: use devenv --impure --option services.postgres.enable:bool true
use devenv
11 changes: 11 additions & 0 deletions docs/automatic-shell-activation.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ To enable automatic shell activation, create an `.envrc` file in your project di
``` bash title=".envrc"
eval "$(devenv direnvrc)"

# You can pass flags to the devenv command
# For example: use devenv --impure --option services.postgres.enable:bool true
use devenv
```

Expand Down Expand Up @@ -52,6 +54,15 @@ Entering shell ...
(devenv) $
```

## Passing flags to devenv

You can pass command-line options directly to devenv by adding them after the `use devenv` command in your `.envrc` file:

```bash
# Example: override configuration options
use devenv --option services.postgres.enable:bool true
```

## Customizing PS1

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