Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Processes are failing to start in flake based config #1153

Closed
nickkadutskyi opened this issue Apr 19, 2024 · 5 comments · Fixed by #1157
Closed

Processes are failing to start in flake based config #1153

nickkadutskyi opened this issue Apr 19, 2024 · 5 comments · Fixed by #1157
Labels
bug Something isn't working macos Affects systems running macOS

Comments

@nickkadutskyi
Copy link

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:

  1. mkdir devenvsh-test && cd $_
  2. nix flake init --template github:cachix/devenv
  3. nix develop --impure
  4. devenv up
  5. 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:

  1. mkdir devenvsh-test && cd $_
  2. nix flake init --template github:cachix/devenv#flake-parts
  3. nix develop --impure
  4. devenv up
  5. 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
@nickkadutskyi nickkadutskyi added the bug Something isn't working label Apr 19, 2024
@dudeofawesome
Copy link

I reverted to devenv version 1.0.3 and that seems to have fixed it for me.

@sandydoo
Copy link
Member

sandydoo commented Apr 21, 2024

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.

@sandydoo sandydoo added the macos Affects systems running macOS label Apr 21, 2024
sandydoo added a commit that referenced this issue Apr 21, 2024
@sandydoo
Copy link
Member

sandydoo commented Apr 21, 2024

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

@sandydoo
Copy link
Member

sandydoo commented Apr 21, 2024

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.

@sandydoo
Copy link
Member

sandydoo commented Apr 21, 2024

@domenkozar, see #1153 (comment). There's 2 ways to fix this:

  1. Re-run mkdir in the procfileScript 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.
  2. Use the DEVENV_RUNTIME env var and modify the devenv.runtime default. One issue here is that devenv.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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working macos Affects systems running macOS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants