Problem using devbox with Phoenix - [error] Can't find executable `mac_listener`

Hey all! Wondering if there is anyone using devbox? Im trying to run a phoenix app but Im getting

[error] Can't find executable `mac_listener`
[warning] Could not start Phoenix live-reload because we cannot listen to the file system.
You don't need to worry! This is an optional feature used during development to
refresh your browser when you save files and it does not affect production.

my devbox.json content is:

{
  "packages": [
    "erlang_26@26.1.2",
    "elixir_1_15@1.15.7",
    "nodejs@18.18.2"
  ],
  "shell": {
    "init_hook": ["echo 'Welcome to devbox!' > /dev/null"],
    "scripts": {
      "test": ["echo \"Error: no test specified\" && exit 1"]
    }
  }
}

I tried adding these packages, but the result is the same:

    "terminal-notifier",
    "darwin.apple_sdk.frameworks.CoreFoundation",
    "darwin.apple_sdk.frameworks.CoreServices"

When I compile the file_system package, Im getting:

❯ mix deps.compile file_system

08:44:09.841 [info] Compiling file system watcher for Mac...
==> file_system
In file included from c_src/mac/cli.c:2:
In file included from c_src/mac/cli.h:4:
c_src/mac/common.h:5:10: fatal error: 'CoreServices/CoreServices.h' file not found
#include <CoreServices/CoreServices.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
In file included from c_src/mac/compat.c:1:
c_src/mac/compat.h:16:10: fatal error: 'CoreServices/CoreServices.h' file not found
#include <CoreServices/CoreServices.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
In file included from c_src/mac/main.c:1:
c_src/mac/common.h:5:10: fatal error: 'CoreServices/CoreServices.h' file not found
#include <CoreServices/CoreServices.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

08:44:10.788 [error] Could not compile file system watcher for Mac, try to run "clang -framework CoreFoundation -framework CoreServices -Wno-deprecated-declarations c_src/mac/*.c -o priv/mac_listener" manually inside the dependency.

Has anyone run into this issue? :pray:

Brief editorializing: I don’t know or endorse Devbox, and I think most people should side-eye any Nix abstraction that doesn’t have you still writing in Nix syntax because at some point or another you’ll want to use or write a Nix expression that i.e. JSON, YAML, or TOML simply can’t express. If you are early on your Nix journey, I would recommend not using a framework at all yet.

A flake with flake-parts for brevity (:stop_sign: on flake-utils-plus) would look something like:

{
  inputs = {
    flake-parts.url = "github:hercules-ci/flake-parts";
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };

  outputs = inputs @ {flake-parts, ...}:
    flake-parts.lib.mkFlake {inherit inputs;} {
      systems = ["aarch64-darwin" "x86_64-linux"];
      perSystem = {
        lib,
        pkgs,
        ...
      }: {
        devShells.default = pkgs.mkShell {
          packages =
            [
              # all your other dependencies
              # see also: https://github.com/shanesveller/nix-beam-flakes/
            ]
            ++ lib.optional pkgs.stdenv.isLinux pkgs.inotify-tools
            ++ lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [CoreServices]);
        };
      };
    };
}

So at a glance you’re providing the correct nixpkgs attribute name for the compile-time dependency (darwin.apple_sdk.frameworks.CoreServices) and most likely it’s a Devbox-specific thing for why that’s either not recognized properly or not made available in the same way a standard devShell does.

1 Like

I just started to look into devbox last week. I currently am using a shell.nix on macOS.

I have only a few global packages setup so far.

I saw this last week, but I am not sure if it’ll help.

I wonder if you need to add one of these packages found in my shell.nix config.

@shanesveller can you call out what was the actual fix for devbox?

I cannot - I didn’t provide any advice that is specific to Devbox since I’m not a user of that tool.

I just grab the json from the example you shared and just worked, I haven’t dug too much on the why, yet.

{
    "packages": [
        "elixir@latest"
    ],
    "env": {
        "MIX_HOME": "$PWD/.nix-mix",
        "HEX_HOME": "$PWD/.nix-hex",
        "ERL_AFLAGS": "-kernel shell_history enabled"
    },
    "shell": {
        "init_hook": [
            "mkdir -p .nix-mix",
            "mkdir -p .nix-hex",
            "mix local.hex --force",
            "mix local.rebar --force",
            "mix deps.get"
        ],
        "scripts": {
            "run_test": "mix run"
        }
    }
}
1 Like

Haha sorry! I thought you were original poster!