Hi all,
I am looking to ultimately use dockerTools.buildImage to efficiently build small releases of Elixir applications. Of course, the first step is to build an Elixir release to put in the image. I would ideally like to have each dependency’s derivation track both from the deps
folder, and also the _build/prod/rel
folder, so that only changed dependencies need to be rebuilt for release, which is why I haven’t gone straight for GitHub - hauleth/nix-elixir.
I spent a long time investigating the options in State of the BEAM Ecosystem in Nix - #28 by anon31783435, but didn’t have any luck, however I was excited to eventually discover that the state of the beam in nixpkgs has been moving along in the meantime! After using GitHub - ydlr/mix2nix: Generate a set of nix derivations from a mix.lock file. to generate the mixNixDeps
for a mixRelease, I took the simplest possible derivation from here https://github.com/NixOS/nixpkgs/blob/5e4ac423de2a69c04e3fe16551dea4c3d6bb4343/doc/languages-frameworks/beam.section.md#mixrelease---example-mix-release-example , ending up with
with import <nixpkgs> { };
let
pname = "your_project";
version = "0.0.1";
src = ./.;
mixNixDeps = with pkgs; import ./mix_deps.nix { inherit lib beamPackages callPackage; };
in beamPackages.mixRelease {
inherit src pname version mixNixDeps;
}
Which I thought would finally do exactly what I wanted! Take each dependency’s derivation, compile it with buildMIx
like so https://github.com/NixOS/nixpkgs/blob/5e4ac423de2a69c04e3fe16551dea4c3d6bb4343/pkgs/development/beam-modules/build-mix.nix#L53, and then build each of those into my mixRelease
at the end.
However, any time I change a single line of code in my Elixir app, when I do nix build
next it does a full recompile of all the dependencies, and I see lots of lines to the effect of
warning: redefining module Plug.Cowboy.Conn (current version loaded from /nix/store/yrhngkisix6s9rfsa8gr28hs0h1q9f6b-plug_cowboy-2.5.1/lib/erlang/lib/plug_cowboy-2.5.1/ebin/Elixir.Plug.Cowboy.Conn.beam)
I’m sure there’s something simple I’m missing, can anyone help please? I am on nix-darwin
and just did a nix-channel --update
on the nixpkgs-unstable
channel.