Help with iterative debugging techniques for package building

Say I have the nix expression for the C++ linear algebra library, petsc locally on my machine in a directory called ./petsc. This contains the files in the link above, namely default.nix and filter_mpi_warnings.patch.

Say I am locally working on debugging this package. How do I run nix-build locally to test the build?

I’ve tried nix-build and nix-build -A petsc but all the required arguments like lib, stdenv, fetchurl, darwin, gfortran , python3, ... are missing. I get the error:

error: cannot evaluate a function that has an argument without a value ('fetchurl')
       Nix attempted to evaluate a function as a top level expression; in
       this case it must have its arguments supplied either by default
       values, or passed explicitly with '--arg' or '--argstr'. See
       https://nixos.org/manual/nix/stable/language/constructs.html#functions.

       at /home/lj/Desktop/petsc/default.nix:3:3:

            2| , stdenv
            3| , fetchurl
             |   ^
            4| , darwin

I’ve tried making a file called build.nix that contains the following"

let
  nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixpkgs-unstable";
  pkgs = import nixpkgs { config = {}; overlays = []; };
in
{
  petsc = pkgs.callPackage ./default.nix { };
}

and running nix-build ./build.nix petsc but this fails as well.

I’m sorry, this seems like it should be so basic. I can make little hello world or simple programs into nix packages no problem, but the moment I have a bunch of build inputs like this, I have no idea how to build it locally.

Edit: turns out my problem had to do with buildPythonPackage and not a failure to pass input arguments to the package.

What does nix-build build.nix say?

1 Like

I figured out the problem and it really had nothing to do with what I said in my question. Sorry about that.

It wasn’t petsc that was failing, but another package, firedrake. This was failing because I had buildPythonPackage as an input to the default.nix and apparently that means I have to call it like this:

firedrake = pkgs.python3Packages.callPackage ./default.nix { };

instead of this:

firedrake = pkgs.callPackage ./default.nix { };

I should have been more careful with my question. Thanks for the help.

2 Likes