Help with my first nix derivation

I am trying to build my first derivation and I am really struggling. I want to install the finite element library called Firedrake. The installation procedure is here:

Basically there are two steps.

  1. get the install script:
    curl -O

  2. install with python:
    python3 firedrake-install

The following was my latest attempt:

{ pkgs ? import <nixpkgs> {} }:

pkgs.stdenv.mkDerivation rec {
  name = "firedrake";

  src = pkgs.fetchurl {
    url = "";
    sha256 = "sha256-HD8g4jQOM1MGm42LMY71zdJVsihvwY6+gnvH40SJzt0";

  nativeBuildInputs = [
     pkgs.util-linux # for lscpu command

  phases = ["installPhase"];

  installPhase = ''
    mkdir -p $out/bin
    cp $src $out/bin/firedrake-install
    chmod +x $out/bin/firedrake-install
    cd $out/bin
    python3 firedrake-install

This is leading to the following error (python modules not found)

error: builder for '/nix/store/b3hhvpvjrhk5r9az20063pzbgp8771mi-firedrake-env.dr       
      last 10 log lines:
       >   File "/nix/store/bl97q3j4anm9w4kv7pdrc8g0nb3y09vv-firedrake-env/bin/f       
       >     from pkg_resources.extern.packaging.version import Version, Invalid       
       > ModuleNotFoundError: No module named 'pkg_resources'
       > During handling of the above exception, another exception occurred:
       > Traceback (most recent call last):
       >   File "/nix/store/bl97q3j4anm9w4kv7pdrc8g0nb3y09vv-firedrake-env/bin/f       
       >     from packaging.version import Version, InvalidVersion
       > ModuleNotFoundError: No module named 'packaging'
       For full logs, run 'nix log /nix/store/b3hhvpvjrhk5r9az20063pzb

I realize that it is not finding the python modules needed for the install script, but I’ve tried putting them in the buildInputs, and nativeBuildInputs, but I can’t get the installer to find them.

The installer did find them when I used the buildPhase instead of the installPhase, but in that case I couldn’t get it to find the CMakeLists.txt file.

I’m really struggling here. Any guidance would be greatly appreciated.

Thank you!

Hello and welcome :wave:

In NixOS merely placing python interpreter with some packages in a dependencies list is not enough. The most direct way of fixing this particular error you have, would be to use python3.withPackages function to make python env with necessary packages (See Nixpkgs Manual). However, it’s also possible that using higher-level function buildPythonApplication instead of a lower-level makeDerivation would be more productive.
All in all, I can give you 2 advises: you should read Nixpkgs manual paragraphs about python packaging to better understand what tools are at your disposal, and also consider taking a look into nixpkgs repo for some examples of python packages.

1 Like


I don’t want to discourage you from trying to make this work, but as far as I could tell, this project has a pretty complicated method of installation.
(you might already have seen that scripts/firedrake-install is pretty long) Trying to make this work well together with the existing python tooling inside Nixpkgs will probably be a challenge, even for more experienced nixpkgs contributors.

I’ll try my hand at this and will get back to you once I get stuck/succeed.

1 Like

Thank you for the advice. I figured this might be the case. I wasn’t sure if I could do what I was attempting to do, or if I needed to rewrite a nix version of that firedrake-install script. I am willing to work on it for a while to try to get it to work. I intend to at one point get to a place where I am a more experienced nixpkgs contributor, and I think it would be very valuable to have firedrake in nixpkgs. I really appreciate your help.

One more thing, it seems like someone has tried to package firedrake for nix in the past. You can see it here

But this was 6 years ago and the installation process has changed since then.

1 Like

I got the main package itself to compile, however many tests are still failing due to me not using the installer script and some git-type python deps not being packaged yet. I think I will be able to get this done sometime.

1 Like

Wow it that is awesome. Thank you very much. I’d love to see what you’ve come up with.

Also, if you have any resources to help me get better at this, I would really appreciate it. I’ve gone through nix-pills and some blogs, but if you have any suggestions on how I can get better at this I’m very eager to learn.

Thanks again.

You can see my progress at GitHub - TomaSajt/nixpkgs at firedrake
there’s still things to do but it shouldn’t be long until it’s done now.

Though, looking at the scope of the changes I’ve made, and the number of firedrake-specific packages, this might have a hard time getting accepted inside Nixpkgs, but it’s not out of the question.
Instead, a separate git repo could be provided with the necessary package definitions.


That is amazing. Thank you so much. I’m going to spend a good chunk of tomorrow trying to understand everything you did and figure out how I can contribute. I really appreciate this. There are a few other finite element libraries that I need to package and this will be invaluable for me to understand how. I can’t thank you enough.

I reached out to the author of the sharcnet git repo I posted above and he sent me a slightly updated version. Still 6 years old but it worked against NixOS 20.09. Not sure if that helps much but I’ll post it here.

Yeah, this is helpful, thanks. Though versions have changed, it’s mostly the same.