Commit 6c8c88c6 authored by Asherah Connor's avatar Asherah Connor
Browse files

buildMix: default to removing target config

See previous discussion at https://github.com/NixOS/nixpkgs/pull/429770.
cc @adamcstephens.

This is equivalent to giving `appConfigPath` an empty directory, but
expresses intent better (and doesn't require throwing an empty directory
into the store).

The Elixir ecosystem assumes [1] that dependencies are compiled without
their config; the `config/` directory is therefore used in library-only
projects to supply config values only intended for use when _developing_
them.  This leads to errors only seen in Nix when compile-time config
lacks runtime equivalents in end-user applications (per the whole
conversation at [1]).

Right now, the only way to get `buildMix` to build without config is to
manually remove the target's config directory in a hook/override, or (as
above) give `appConfigPath` an empty directory.  This PR adds a clearer
mechanism, and makes it the default.

[1] https://github.com/dashbitco/lazy_html/pull/11#issuecomment-3138715485

Tested with a `mix2nix`-using package that this functions as expected,
and with some `deps_nix`-using ones that `appConfigPath` still does too.
parent ed33ba16
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -25,12 +25,15 @@
  meta ? { },
  enableDebugInfo ? false,
  mixEnv ? "prod",
  removeConfig ? true,
  # A config directory that is considered for all the dependencies of an app, typically in $src/config/
  # This was initially added, as some of Mobilizon's dependencies need to access the config at build time.
  appConfigPath ? null,
  ...
}@attrs:

assert appConfigPath != null -> removeConfig;

let
  shell =
    drv:
@@ -79,10 +82,17 @@ let
            runHook preConfigure

            ${./mix-configure-hook.sh}
            ${lib.optionalString (removeConfig && isNull appConfigPath)
              # By default, we don't want to include whatever config a dependency brings; per
              # https://hexdocs.pm/elixir/main/Config.html, config is application specific.
              ''
                rm -rf config
                mkdir config
              ''
            }
            ${lib.optionalString (!isNull appConfigPath)
              # Due to https://hexdocs.pm/elixir/main/Config.html the config directory
              # of a library seems to be not considered, as config is always
              # application specific. So we can safely delete it.
              # Some more tightly-coupled dependencies do depend on the config of the application
              # they're being built for.
              ''
                rm -rf config
                cp -r ${appConfigPath} config