devenv
devenv copied to clipboard
Processes are failing to start in flake based config
Describe the bug
Running devenv up
in nix develop --impure
shell fails in flake config based on default flake template:
❯ nix flake init --template github:cachix/devenv
wrote: /Users/nick/Developer/PE/Test/devenvsh-2/.envrc
wrote: /Users/nick/Developer/PE/Test/devenvsh-2/.gitignore
wrote: /Users/nick/Developer/PE/Test/devenvsh-2/flake.nix
.devenv should be added to .gitignore
| echo .devenv >> .gitignore
direnv: error /Users/nick/Developer/PE/Test/devenvsh-2/.envrc is blocked. Run `direnv allow` to approve its content
❯ nix develop --impure
warning: creating lock file '/Users/nick/Developer/PE/Test/devenvsh-2/flake.lock'
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
Hello, world!
(devenv) Nicks-MacBook-Air:devenvsh-2 nick$ devenv up
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
{"level":"warn","error":"open /Users/nick/Library/Application Support/process-compose/settings.yaml: no such file or directory","time":"2024-04-19T09:55:37-07:00","message":"Error reading settings file /Users/nick/Library/Application Support/process-compose/settings.yaml"}
24-04-19 09:55:37.351 FTL start UDS http server on /tmp/nix-shell.2W2rLL/devenv-76311b3/pc.sock failed error="listen unix /tmp/nix-shell.2W2rLL/devenv-76311b3/pc.sock: bind: no such file or directory"
(devenv) Nicks-MacBook-Air:devenvsh-2 nick$ hello
Hello, world!
When I use flake-parts
flake template it fails in a different way. I get the same error when I run devenv up
on fresh template or if I add some process (processes.run.exec="hello"
) in devenv.shells.default
:
❯ mkdir devenvsh-test && cd $_
❯ nix flake init --template github:cachix/devenv#flake-parts
wrote: /Users/nick/Developer/PE/Test/devenvsh-test/.envrc
wrote: /Users/nick/Developer/PE/Test/devenvsh-test/.gitignore
wrote: /Users/nick/Developer/PE/Test/devenvsh-test/flake.nix
.devenv should be added to .gitignore
| echo .devenv >> .gitignore
direnv: error /Users/nick/Developer/PE/Test/devenvsh-test/.envrc is blocked. Run `direnv allow` to approve its content
❯ nix develop --impure
warning: creating lock file '/Users/nick/Developer/PE/Test/devenvsh-test/flake.lock'
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
Hello, world!
(devenv) Nicks-MacBook-Air:devenvsh-test nick$ devenv up
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error:
… while evaluating the attribute 'optionalValue.value'
at /nix/store/cb1gs888vfqxawvc65q1dk6jzbayh3wz-source/lib/modules.nix:856:5:
855|
856| optionalValue =
| ^
857| if isDefined then { value = mergedValue; }
… while evaluating a branch condition
at /nix/store/cb1gs888vfqxawvc65q1dk6jzbayh3wz-source/lib/modules.nix:857:7:
856| optionalValue =
857| if isDefined then { value = mergedValue; }
| ^
858| else {};
(stack trace truncated; use '--show-trace' to show the full trace)
error: attribute 'config' missing
at /nix/store/phs98p6gj4hah80xb5gm7kqkinai6qls-source/flake.nix:34:30:
33| # needed for devenv up
34| packages.devenv-up = self'.devShells.default.config.procfileScript;
| ^
35|
(devenv) Nicks-MacBook-Air:devenvsh-test nick$
To reproduce For default flake template:
-
mkdir devenvsh-test && cd $_
-
nix flake init --template github:cachix/devenv
-
nix develop --impure
-
devenv up
- Instead of running services I get
FTL start UDS http server on /tmp/nix-shell.kxqGNh/devenv-76311b3/pc.sock failed error="listen unix /tmp/nix-shell.kxqGNh/devenv-76311b3/pc.sock: bind: no such file or directory"
error
Or for flake-parts
template:
-
mkdir devenvsh-test && cd $_
-
nix flake init --template github:cachix/devenv#flake-parts
-
nix develop --impure
-
devenv up
- Instead of running services I get
error: attribute 'config' missing
error.
Version
❯ devenv version
devenv 1.0.4 (aarch64-darwin)
❯ nix --version
nix (Nix) 2.18.2
I reverted to devenv version 1.0.3
and that seems to have fixed it for me.
Regular flake
I can successfully run devenv up
inside a direnv
shell, but it fails when run from a shell created with nix develop --impure
. Not sure what the issue is yet.
Flake-parts
We need to remove this line from the template: packages.devenv-up = self'.devShells.default.config.procfileScript;
.
This fixes the error, but I then run into the same issue as the regular flake.
The socket isssue is macos-specific.
Our runtime dir is: DEVENV_RUNTIME=/tmp/devenv-8e7ea8e
The tmp dir in nix develop --impure
shell is: TMP=/tmp/nix-shell.uRu0AU
process-compose is looking for the socket in: /tmp/nix-shell.uRu0AU/devenv-8e7ea8e/pc.sock
I believe what's happening is that devenv never creates the /tmp/nix-shell.uRu0AU/devenv-8e7ea8e
directory.
Before nix develop
takes over the shell, the runtime dir is set to /tmp/devenv-<hash>
and created.
After nix develop
, nix sets TMPDIR
to /tmp/nix-shell.<hash>
, which then changes the runtime dir to /tmp/nix-shell.<hash>/devenv-<hash>
. This dir is never created.
The reason this doesn't happen on NixOS is because XDG_RUNTIME_DIR
is set by default, which takes precedence over TMPDIR
in devenv.
And direnv
's nix integration unsets TMPDIR
, which is why it also works.
@domenkozar, see https://github.com/cachix/devenv/issues/1153#issuecomment-2068078326. There's 2 ways to fix this:
- Re-run
mkdir
in theprocfileScript
to create the new runtime dir. Could be problematic if anything is put into the original runtime dir on shell creation and is required later on. - Use the
DEVENV_RUNTIME
env var and modify thedevenv.runtime
default. One issue here is thatdevenv.tmpdir
gets updated to/tmp/nix-shell.<hash>
, but nothing seems to be using this.
Alternatively, maybe we can create the runtime dir in a script passed to nix develop
? Would this work?