beamPackages.buildMix: compile non-deterministic deps in $out/src - #506184
beamPackages.buildMix: compile non-deterministic deps in $out/src#506184ju1m wants to merge 1 commit into
Conversation
$out/src and disable erlangDeterministicBuilds by default
|
Why is it necessary to change the global default for this? Can't surface, or other packages, disable deterministic individually? |
|
@adamcstephens
Source: https://www.erlang.org/doc/apps/compiler/compile.html From my somewhat limited experience in packaging Elixir in Nix, That's why I propose to stick to Erlang's default, which is to not enable |
|
This is going to need a full nixpkgs-review, and probably build some of the nixos tests for elixir apps in tree. Furthermore I’m not comfortable merging this until at least after branch off for 26.05, to avoid unexpected consequences. I’d also be worried that this will leave a bunch of extra artifacts in the output. |
|
As I remember, quite a bit of effort was put into enabling cc @NixOS/beam |
The short answer is that it's about not bloating the resulting derivation with unnecessary runtime dependencies. Take a look at the PR that introduced |
This is the more correct way of stating what I hinted at in my comment about extra artifacts. I can see this being a real problem. For example a mixRelease package generally bundles erts in the package itself. If its closure also pulled in erlang and its dependencies, that could be 300-1300MB+ of extra unnecessary dependencies. As I've reflected on this more, we shouldn't change the default on deterministic builds, but we could improve the support for those who want to disable them. That means potentially a modification to a hook, or an extra hook, that will ensure that we get a proper output when they're disabled. |
$out/src and disable erlangDeterministicBuilds by default$out/src
|
There was a problem hiding this comment.
I would like to see us change sourceRoot only in the case of non-deterministicBuilds. mix doesn't necessarily keep the source directory clean of artifacts, especially when working with native code.
I expect src to be a clean copy of the source itself, without any build artifacts that mix may create, so I'd also consider it more correct for non-deterministicBuilds to delete and re-copy the original src after building is done. This would provide the same clean slate as the deterministicBuilds scenario. This is less of a blocker for me, but from what I've seen you probably don't want the artifacts mix leaves around.
|
Turned this PR into a draft and pushed some changes to address latest concern raised, but cannot test yet.
|
|
surface writes to config?!? could they, not? that seems like a bad practice that we're enabling instead of pushing back on. |
I don't know but the way Bonfire (not in Nixpkgs, yet) uses it, $ nix -L build -f. bonfire.ember.mixNixDeps.surface_form_helpers
[…]
erlang27.3.4.7-surface_form_helpers> Generated surface_form_helpers app
erlang27.3.4.7-surface_form_helpers> <- Ran mix compile.app in 4ms
erlang27.3.4.7-surface_form_helpers> -> Running mix compile.surface --no-deps-check (inside Surface.Form.MixProject)
erlang27.3.4.7-surface_form_helpers> ** (File.Error) could not remove file "/nix/store/7ya12s6c62v1kq3bv18skii86lwrcg6w-erlang27.3.4.7-surface_form_helpers-0.2.0/src/config/current_flavour/assets/hooks/Bonfire.Editor.Milkdown.hooks.js": permission denied
erlang27.3.4.7-surface_form_helpers> (elixir 1.18.4) lib/file.ex:1222: File.rm!/1
erlang27.3.4.7-surface_form_helpers> (elixir 1.18.4) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2
erlang27.3.4.7-surface_form_helpers> (surface 0.12.3) lib/mix/tasks/compile/surface.asset_generator.ex:312: Mix.Tasks.Compile.Surface.AssetGenerator.delete_unused_hooks_files!/2
erlang27.3.4.7-surface_form_helpers> (surface 0.12.3) lib/mix/tasks/compile/surface.asset_generator.ex:191: Mix.Tasks.Compile.Surface.AssetGenerator.generate_js_files/2
erlang27.3.4.7-surface_form_helpers> (surface 0.12.3) lib/mix/tasks/compile/surface.asset_generator.ex:35: Mix.Tasks.Compile.Surface.AssetGenerator.do_run/2
erlang27.3.4.7-surface_form_helpers> (surface 0.12.3) lib/mix/tasks/compile/surface.ex:198: Mix.Tasks.Compile.Surface.do_run/1
erlang27.3.4.7-surface_form_helpers> (mix 1.18.4) lib/mix/task.ex:495: anonymous fn/3 in Mix.Task.run_task/5
erlang27.3.4.7-surface_form_helpers> (stdlib 6.2.2.2) timer.erl:595: :timer.tc/2I can gate that behind a |
|
Are you sure that’s not a misconfiguration or maybe can be configured to write elsewhere? I wouldn’t expect assets, js or really any content to generate into config. |
|
https://surface.hexdocs.pm/Mix.Tasks.Compile.Surface.html#module-options
Why it's trying to delete project files is a bit unclear to me. Can you share your build target? Is it https://github.com/bonfire-networks/bonfire-app on main? |
|
@adamcstephens I'm currently packaging Bonfire in NGIpkgs here: ngi-nix/ngipkgs#2155 #cp --no-preserve=mode -r "${appConfigPath}" config
ln -sf "${appConfigPath}" config
|
|
Have you considered using mixFodDeps instead? I wonder if this would make your life easier, at the cost of rebuild efficiency. |
Ah, yes, it would, But I've been struggling/able to avoid it up to now, because it undermines the added value of using |
$out/src|
I've taken a stab at a new PR title. Can you update the commit to something similar? |
`mix compile.surface` or `Fine.include_dir()` use `module_info/1` to get source files of BEAM dependencies. To work this requires: 1. `erlangDeterministicBuilds` set to `false` to preserve the build directory in `.beam` files. 2. to build dependencies in a directory persisting across nix builds: `$out/src` instead of `/build/source`. Issue: surface-ui/surface#762
This is necessary to support
mix compile.surfaceorFine.include_dir().Used by #550073
DefaulterlangDeterministicBuildstofalsebecause it breaks apps using Surface
and does not improve determinism within a sandboxed nix build which always builds in the same path anyway.
EDIT: keep
erlangDeterministicBuildstotrueby default because it apparently increases the closure size.Yet, disabling
erlangDeterministicBuildsis not enough formix compile.surfaceto work across packages, as it:Since
beamCopySourceHookonly copies$srcinto$out/src, that is not enough:module_info/1will return a path in/build/sourceinstead of a path in$out/src,therefore build into
$out/src, which will remain reachable after the build.Issue: surface-ui/surface#762
Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.