Nix-elixir and dependencies with port compilation?

I am exploring Nix (and eventually NixOS) by packaging an OCI container for my personal website project, a Elixir Phoenix application which is distributed as org-mode documents.

I integrated @hauleth 's nix-elixir pretty easily so far with this default.nix but I am having an issue with one of my transitive dependencies: it uses a rebar3 plugin port_compiler which it attempts to download in the sandboxed configurePhase … I see that buildRebar3 can be directed to install and configure pc with compilePorts and whatnot but I’m not sure how to use the rebar3-nix-bootstrap in my derivation while keeping things pure, and i’m not sure how to structure this to be able to feed a bootstrapped rebar3 in to the configurePhase of my buildMix derivation.

i’ll admit, starting with an elixir project doesn’t seem like the best place to start learning how all these things are fit together but I’ve got to start somewhere and I’ve been bikeshedding on how to build docker images for this project for a while … I’m still quite green, reading through docs and the nix pills so bear with me if there’s an easy way to do this that I’m not considering.

as an aside, my first attempt here I was using a standard FOD derivation I’d constructed myself around a unsandbox’d mix distillery.release in the buildPhase but I was getting some obscure execve failures from erlexec trying to spawn EPMD when I started the docker container, so i moved to mix release and nix-elixir where I am now. I’m not sure this will resolve those issues since I haven’t got it to build yet and anyways the code and buildinputs are still basically the same, but I had a real fun time learning about Nix while learning about erlang release and bootup!

(I have two replies below that were written before this most recent update, sorry. It’s been a while since i’ve been on forums!)

1 Like

rebar3-release uses the same rebar3-nix-bootstrapper script as buildRebar3, and so I thought that I can do something simple like:

pkgs.beam.packages.erlang.buildMix' {
  rebar3 = pkgs.rebar3.override { compilePort = true; };

or else make a package that i can use as buildInputs but I don’t understand the override and overlay stuff enough yet to work this out.

1 Like

i guess if that nixpkgs.rebar3 derivation doesn’t know about the attributes I can’t override them… Should I go read the contributor docs and add the compilePorts and buildPlugins attributes to the pkg derivation on github ?

1 Like

I’m not familiar enough with rebar3 to fully understand what you’re doing, but if compilePorts and buildPlugins are actually attributes I believe you would need to use overrideAttrs instead of override to modify them. Just override allows you to override function arguments. This is the relevant section from the manual.

1 Like

i spent some more time on this over the weekend with clearer eyes and another look at that documentation, thanks for pointing me back towards it. I still haven’t got it working, but I do have a better understanding of things…

  • erlang/elixir nixpkgs layout really makes things tougher to consider from the outside but this packagesWith helper is used to inject the new derivations in to the various interpreter configurations under nixpkgs.beam.interpreters and i use that in my default.nix
  • nix-elixir/build-mix.nix at 8bdf6e73e3c5fa0706b2d1936bceb1baf692ed96 · hauleth/nix-elixir · GitHub inherits a bunch of stuff out of nixpkgs for its initialization function call based on my understanding of how callPackage works so I should be able to override these since that is a function call and not a derivation; if i can do so, I can override it with a rebar3 derivation which has the attribute overridden: rebar3.overrideAttrs(oldAttrs: { compilePorts=true; });

I figure the right way to do this is probably in an overlay applied before nix-elixir is applied. so i used that packagesWith pattern to define an overlay which does cause a custom derivation of rebar3 to come in to the buildMix'' derivation and my buildMix'' derviation is invoked, but the buildPhase fails still trying to install the port compiler plugin for one of my deps…

I am not sure how to tell if my overlay worked, and if it did work I can’t tell if fetchMixDeps is using it, and it’s not clear to me how to proceed; the rebar.config in my rebar3 source directory doesn’t have the pc configuration in it

I’m going to just shelve this i guess until RFC fixing build-mix · Issue #105002 · NixOS/nixpkgs · GitHub is completed and then try using that in whatever form it shapes up to …

1 Like

okay the rebar3-nix-bootstrapper script isn’t used by the rebar3/default.nix itself any more… that was removed in one commit and partially restored later on… what a red herring. Invoking the bootstrapper did help, and I wedged in a rebar3 built with the pc plugin but it still tried to update itself during the configurationPhase

1 Like