0

I now understand how to write a basic shell.nix the a project that I am developing. I have something like this:

{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
  nativeBuildInputs = with pkgs; [ 
    cmake
    boost
    eigen
  ];
}

There is, however, one more package (e.g., cln) this project depends on that I need to download the source from a git repository and compile with some special flags. The package uses autoconf, and I simply need to enable/disable a few options. I am not sure how to achieve this in this shell.nix. The following is my current attempt, which I piece together from various google searches. It does not work, and I have no clue how to fix it (or how to search for help):

with import <nixpkgs> {};

stdenv.mkDerivation {    # this line causes an error
  name = "cln-m1";
  src = fetchurl {
    url = "https://www.ginac.de/CLN/cln-1.3.6.tar.bz2";
  };    # I also want to pass some flags to "configure" here
}

pkgs.mkShell {
  nativeBuildInputs = with pkgs; [ 
    cmake
    boost
    eigen
    cln-m1    # this is the customized package I want to add
  ];
}

This code does not work as the stdenv.mkDerivation... line produces the error:

error: attempt to call something which is not a function but a set

I would like to fix that and be able to pass some flags into the configure script of cln before building it and use the customized cln (cln-m1) as the dependency for this shell.

3
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Mar 10, 2023 at 8:19
  • Let's break it up into two parts. First, write a cln.nix that you can build with nix-build cln.nix that builds the software you are interested in. If it succeeds, it will make a result symlink in your current directory and you can inspect the result and try running it to make sure it's OK. Then write a shell.nix that has an import statement to import cln.nix and add it to the nativeBuildInputs list. Which of those two steps are you struggling with and what is the specific part you are getting stuck on? Commented Dec 28, 2023 at 17:37
  • You're getting the error message "attempt to call something which is not a function" because you're just slapping unrelated bits of code together in the same file without a concept of how the Nix language syntax works. Recommended reading: nixos.org/manual/nix/stable/language/index.html Specifically, when you write "A B" Nix usually assumes A is a function and B is an argument to it, so it thinks you are trying to pass your pkgs.mkShell stuff as an argument to the stuff that came before it, which is not even a function. Commented Dec 28, 2023 at 17:41

1 Answer 1

0

Well, it's like basic functional programming.

with import <nixpkgs> {};
let
  cln-m1 = stdenv.mkDerivation {    # this line causes an error
    name = "cln-m1";
    src = fetchurl {
      url = "https://www.ginac.de/CLN/cln-1.3.6.tar.bz2";
    };    # I also want to pass some flags to "configure" here
  };

in pkgs.mkShell {
  nativeBuildInputs = with pkgs; [ 
    cmake
    boost
    eigen
    cln-m1    # this is the customized package I want to add
  ];
}
1
  • I mean, this is just showing the composition part. Here I'm not trying to address how to write packages, i.e. stdenv.mDerivation and all contained inside its call - that's unrelated to nix-shell. Commented Mar 12, 2023 at 10:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .