Skip to content

Using enacl as a dependency in a Nix derivation of an Elixir project #75

Description

@cognivore

To whom it may concern,

Elixir test task we build for my startup use enacl for cryptography, however when we started moving to nix-docker, which is the best Docker image compilation backend (better than docker!), we needed to nixify all the dependencies too.

While hex dependencies worked with no problem, enacl couldn't build. That's why after a lot of digging and thinking, @ixahedron has produced the following pearl:

      packages.default = beamPackages.mixRelease rec {
        pname = "on_the_map-goo";
        version = "0.1.0";

        src = ./.;

        buildInputs = allBuildInputs;

        mixNixDeps = (import ./deps.nix) {
          inherit beamPackages;
          lib = pkgs.lib;

          # enacl is a pain in the ass. Heed my warnings.
          overrides = (final: prev: {
            # deps_nix and autofetchers treat it as a mix dependency even
            # though it's specified for rebar3.
            enacl = beamPackages.buildRebar3 {
              version = "46e2754a50f4d9192ebf008bf80ea8242e7f7986";
              name = "enacl";

              # Maybe that's why fetching it from hex, where it DOES EXIST,
              # fail for some reason.
              src = builtins.fetchGit {
                url = "https://github.com/jlouis/enacl.git";
                rev = "46e2754a50f4d9192ebf008bf80ea8242e7f7986";
                allRefs = true;
              };

              # Then, it fails to compile, as rebar3's pc plugin is unavailable.
              compilePorts = true;
              buildPlugins = [ beamPackages.pc ];

              # Also, it won't pick up mixRelease's buildInputs, so we need
              # to pass libsodium explicitly.
              buildInputs = [ pkgs.libsodium ];
            };
          });
        };

      };

Sorry to abuse Github issues (and, of course, feel free to close), but this needs to be indexed by search engines!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions