Nix-darwin: paperless-ngx and teslamate

Hi,

I’m new to Nix and nix-darwin. I’ve ended up in this rabbit hole because I recently migrated my homelab from a Synology NAS to a Mac Studio and now that Docker isn’t the only game in town anymore when it comes to running services, I’m replacing most containers with native solutions provided by package managers.

I’ve started out with Homebrew because that’s what I’m familiar with, but found that there are no formulae for more complex applications like paperless-ngx and teslamate. There are Nix packages for both (and home-manager seems like a nice-to-have as well), so I downloaded the Determinate installer and set up a flake using nix-darwin.

Moving brews, casks, and taps over and using Nix packages where available was a breeze. But I got stuck with the two packages mentioned above. First, Teslamate:

It provides a flake (teslamate/flake.nix at a7d4e267da25d9f5d3e979d82c6d135d80747655 · teslamate-org/teslamate · GitHub) which I’ve added to the inputs:

    teslamate = {
      url = "github:teslamate-org/teslamate/main";
      inputs.nixpkgs.follows = "nixpkgs";
    };

The project provides a module (teslamate/nix/module.nix at a7d4e267da25d9f5d3e979d82c6d135d80747655 · teslamate-org/teslamate · GitHub) which provides a services with a nice configuration surface, but as far as I understood, this is for NixOS only, right? Is nix-darwin restricted to the comparatively small set of services (services - MyNixOS) or is there a way to leverage other services (replacing systemd with launchd)? For example, how would I run Grafana as a service on Darwin?

Assuming that a service is unavailable, I continued with adding teslamate.packages.aarch64-darwin.default to environment.systemPackages and ran darwin-rebuild build which ended up with this error:

error: builder for '/nix/store/bbbm5jnz4if25yprdz9jbi792x4vqc70-teslamate-2.0.1-dev.drv' failed with exit code 1;
       last 25 log lines:
       > ==> phoenix
       > Compiling 71 files (.ex)
       > Generated phoenix app
       > ==> phoenix_live_view
       > Compiling 39 files (.ex)
       > Generated phoenix_live_view app
       > ==> phoenix_ecto
       > Compiling 7 files (.ex)
       > Generated phoenix_ecto app
       > ==> cloak_ecto
       > Compiling 22 files (.ex)
       > Generated cloak_ecto app
       > configurePhase completed in 32 seconds
       > Running phase: buildPhase
       > Compiling 78 files (.ex)
       >
       > == Compilation error in file lib/teslamate_web/cldr.ex ==
       > ** (File.Error) could not write to file "/nix/store/xrh3fjc2cv9rfi30gp3050p64yz0cc47-source/priv/cldr/locales/da.json": permission denied
       >     (elixir 1.17.3) lib/file.ex:1144: File.write!/3
       >     (ex_cldr 2.42.0) lib/cldr/install.ex:107: Cldr.Install.do_install_locale_name/3
       >     (elixir 1.17.3) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2
       >     (ex_cldr 2.42.0) lib/cldr/install.ex:29: Cldr.Install.install_known_locale_names/1
       >     (ex_cldr 2.42.0) lib/cldr.ex:102: Cldr.install_locales/1
       >     (ex_cldr 2.42.0) expanding macro: Cldr.Backend.Compiler.__before_compile__/1
       >     lib/teslamate_web/cldr.ex:1: TeslaMateWeb.Cldr (module)

At that point, I asked in the project’s GitHub Discussions and moved on to paperless-ngx package. Applying the config yielded another error messsage:

       … while evaluating the option `system.activationScripts.script.text':

       … while evaluating definitions from `/nix/store/1cz4yck4apraki4mq8xmj8mpp50brp54-source/modules/system/activation-scripts.nix':

       … while evaluating the option `system.activationScripts.applications.text':

       … while evaluating definitions from `/nix/store/1cz4yck4apraki4mq8xmj8mpp50brp54-source/modules/system/applications.nix':

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: Package ‘postgresql-test-hook’ in /nix/store/9pcp2lj1jxfdwbf690kwz6v1yjykl3km-source/pkgs/build-support/trivial-builders/default.nix:80 is marked as broken, refusing to evaluate.

I followed the instructions, set NIXPKGS_ALLOW_BROKEN=1 and ran the command again with --impure, but it failed again while building a Python dependency:

error: builder for '/nix/store/6andwcb0brbkncvinpkxdna8zpbrrs91-python3.12-debugpy-1.8.14.drv' failed with exit code 1;
       last 25 log lines:
       >
       > [gw8] node down: Not properly terminated
       > F
       > replacing crashed worker gw8
       > 15 workers [845 items]   ......sss..................s........ssss.............s.............sss.........s....................s.............................................ss.ssssssss.s.sss...sss..sss.ssss....ssss.....s..........s.....................................................................................................                                                                          [100%]
       > =================================== FAILURES ===================================
       > _________________________ tests/debugpy/test_django.py _________________________
       > [gw8] darwin -- Python 3.12.9 /nix/store/xzjghvsg4fhr2vv6h4scihsdrgk4i76w-python3-3.12.9/bin/python3.12
       > worker 'gw8' crashed while running 'tests/debugpy/test_django.py::test_django_breakpoint_no_multiproc[launch-code]'
       > =============================== warnings summary ===============================
       > ../../../../nix/store/bd6b45r03gsm8x5awyyi4vsysrfqsxhj-python3.12-pytest-8.3.5/lib/python3.12/site-packages/_pytest/fixtures.py:1313: 30 warnings
       >   /nix/store/bd6b45r03gsm8x5awyyi4vsysrfqsxhj-python3.12-pytest-8.3.5/lib/python3.12/site-packages/_pytest/fixtures.py:1313: PytestRemovedIn9Warning: Marks applied to fixtures have no effect
       >   See docs: https://docs.pytest.org/en/stable/deprecations.html#applying-a-mark-to-a-fixture-function
       >     return fixture_marker(fixture_function)
       >
       > -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
       > =========================== short test summary info ============================
       > FAILED tests/debugpy/test_django.py::test_django_breakpoint_no_multiproc[launch-code]
       > ===== 1 failed, 744 passed, 100 skipped, 30 warnings in 146.91s (0:02:26) ======

Am I just holding it wrong or did I just have bad luck with the two packages?