# Nix-elixir and dependencies with port compilation?

**URL:** https://discourse.nixos.org/t/nix-elixir-and-dependencies-with-port-compilation/11208
**Category:** Help
**Created:** [January 27, 2021, 1:43am UTC](https://discourse.nixos.org/t/nix-elixir-and-dependencies-with-port-compilation/11208 "2021-01-27T01:43:33Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![rrix](https://discourse.nixos.org/user_avatar/discourse.nixos.org/rrix/32/3673_2.png) [@rrix](https://discourse.nixos.org/u/rrix)
#### Post date: [January 27, 2021, 1:43am UTC](https://discourse.nixos.org/t/nix-elixir-and-dependencies-with-port-compilation/11208/1 "2021-01-27T01:43:33Z")

</div>

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](https://orgmode.org) documents.

I integrated @hauleth 's nix-elixir pretty easily so far with this [default.nix](https://code.rix.si/rrix/arcology/src/branch/nix-docker-checkpoint/default.nix) but I am having an issue with one of my transitive dependencies: it uses a `rebar3` plugin [port\_compiler](https://github.com/blt/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](https://github.com/erlang/otp/blob/fc2f596851e4676933c5e4dbf398e7020af04ad2/erts/etc/common/erlexec.c#L1270) 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!

[https://code.rix.si/rrix/arcology/src/branch/nix-docker-checkpoint/default.nix](https://code.rix.si/rrix/arcology/src/branch/nix-docker-checkpoint/default.nix)

(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!)

---

<div class="post-metadata">

### Author: ![rrix](https://discourse.nixos.org/user_avatar/discourse.nixos.org/rrix/32/3673_2.png) [@rrix](https://discourse.nixos.org/u/rrix)
#### Post date: [January 27, 2021, 2:19am UTC](https://discourse.nixos.org/t/nix-elixir-and-dependencies-with-port-compilation/11208/2 "2021-01-27T02:19:52Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

### Author: ![rrix](https://discourse.nixos.org/user_avatar/discourse.nixos.org/rrix/32/3673_2.png) [@rrix](https://discourse.nixos.org/u/rrix)
#### Post date: [January 27, 2021, 2:40am UTC](https://discourse.nixos.org/t/nix-elixir-and-dependencies-with-port-compilation/11208/3 "2021-01-27T02:40:50Z")

</div>

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 ?

---

<div class="post-metadata">

### Author: ![mayl](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mayl/32/6111_2.png) [@mayl](https://discourse.nixos.org/u/mayl)
#### Post date: [February 15, 2021, 7:10am UTC](https://discourse.nixos.org/t/nix-elixir-and-dependencies-with-port-compilation/11208/4 "2021-02-15T07:10:56Z")

</div>

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](https://nixos.org/manual/nixpkgs/stable/#chap-overrides).

---

<div class="post-metadata">

### Author: ![rrix](https://discourse.nixos.org/user_avatar/discourse.nixos.org/rrix/32/3673_2.png) [@rrix](https://discourse.nixos.org/u/rrix)
#### Post date: [February 22, 2021, 1:41am UTC](https://discourse.nixos.org/t/nix-elixir-and-dependencies-with-port-compilation/11208/5 "2021-02-22T01:41:35Z")

</div>

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](https://github.com/hauleth/nix-elixir/blob/8bdf6e73e3c5fa0706b2d1936bceb1baf692ed96/default.nix#L4-L10) 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
- [https://github.com/hauleth/nix-elixir/blob/8bdf6e73e3c5fa0706b2d1936bceb1baf692ed96/lib/build-mix.nix](https://github.com/hauleth/nix-elixir/blob/8bdf6e73e3c5fa0706b2d1936bceb1baf692ed96/lib/build-mix.nix) 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](https://code.rix.si/rrix/arcology/src/branch/nix-docker-checkpoint/rebar-overlay.nix) 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](https://github.com/NixOS/nixpkgs/issues/105002) is completed and then try using that in whatever form it shapes up to …

---

<div class="post-metadata">

### Author: ![rrix](https://discourse.nixos.org/user_avatar/discourse.nixos.org/rrix/32/3673_2.png) [@rrix](https://discourse.nixos.org/u/rrix)
#### Post date: [February 22, 2021, 3:41am UTC](https://discourse.nixos.org/t/nix-elixir-and-dependencies-with-port-compilation/11208/6 "2021-02-22T03:41:05Z")

</div>

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`…
