3

Currently I am having some trouble using an Idris package that was installed with nixpkg in another Idris package that depends on it. Both of these packages have been tested on a Debian system, so the problem is not with the Idris code itself, but rather somewhere in how they are being installed on the NixOS system. I believe I can successfully install the first package by calling nix-env -f math.nix -i idris_math where math.nix is defined as:

with import <nixpkgs> { };

stdenv.mkDerivation rec {
  name = "idris_math";
  idris = haskellPackages.idris;
  buildDepends = [ idris ];
  src = ./.;

  preHook = ''
    ln -sv ${idris}/share/x86_64-linux-ghc-8.0.1/${idris.name}/libs $PWD/libs
    export IDRIS_LIBRARY_PATH=$PWD/libs
  '';

  configurePhase = ''
    export TARGET=$out/lib/${idris.name}
  '';

  buildPhase = ''
      ${idris}/bin/idris --build *.ipkg
  '';

  installPhase = ''
    ${idris}/bin/idris --install *.ipkg
    ${idris}/bin/idris --clean *.ipkg
  '';

  }

I can then run nix-env -q and see that idris_math has been installed. The second nixpkg looks identical to math.nix, except the name is changed and the buildDepends line is now buildDepends = [ idris idris_math ]. When I try to build or install this package however, I am met with error: undefined variable 'idris_math'. Does anyone know what I am doing wrong, or of a way to fix this?

  • You'll have to make Nix aware of what `idris_math` is and this is not achieved by installing it. One way would be using `packageOverride` as explained here: https://nixos.org/nixpkgs/manual/#sec-modify-via-packageOverrides – Zimm i48 Mar 19 '17 at 17:42

1 Answers1

0

When you write with import <nixpkgs> {}, every attribute defined in the Nixpkgs set is essentially made into a local variable. This means that, when you write haskellPackages, for example, you are actually referring to the haskellPackages attribute defined by Nixpkgs. You can see all the packages defined this way by looking at the file top-level/all-packages.nix in your Nixpkgs checkout.

Notice that the idris in your buildDepends is referring to the definition of an idris attribute on the previous line. Your new idris_math package isn't similarly defined in this file, or added to the Nixpkgs set anywhere, so you can't get a reference to it by looking for a local variable or for (import <nixpkgs> {}).idris_math, which is basically what is being attempted when you write idris_math in your second derivation.

Depending on what exactly you want to do with your package, you have a couple of options. If you just want to use idris_math as a dependency for another nearby package (or a few), you can just write buildDepends = [ idris (import /path/to/math.nix) ]. This is a very simple way to do what you want, and very likely a good choice if you want to use this is a library when developing Idris packages.

If you want to make idris_math part of the set that you get from import <nixpkgs> {} anywhere on your machine, and to make it easy to nix-env -i, you can try adding it to an overlay. This would require creating a file like ~/.config/nixpkgs/overlays/<my overlay name>/default.nix with contents something like:

self: super:

with super;

{
  idris_math = callPackage /path/to/idris_math.nix {};
}

In this scenario, you probably also want to change your idris_math.nix header to be { stdenv, haskellPackages }:, because callPackage looks for this kind of definition and it is useful when tying the knot to combine all the overlays together.

Peter Amidon
  • 1,435
  • 5
  • 14