Chris Stryczynski
Chris Stryczynski

Reputation: 34001

How to use Nix niv to reference github project?

I'm currently using the following to pin the nixpkgs to make a project reproducible (with https://github.com/nmattia/niv):

{
  nixpkgs ? import <nixpkgs> {}
, compiler ? "default"
, doBenchmark ? false
, sources ? import ./nix/sources.nix
}:

let

  niv = import sources.nixpkgs {
    overlays = [
      (_ : _ : { niv = import sources.niv {}; })
    ] ;
    config = {};
  };
  inherit (niv) pkgs;
...

With the above, I can nix-build successfully, though I'm not 100% sure it's using niv to pin the packages as intended.

None the less, I'm now trying reference a github project - but I run into an error (...called without required argument...)?

My attempt:

After running niv add ...:

nix-shell
error: 'f' at /home/chris/fromLaptopt/usbflash/Haskell/UraniumZuluGooseberry/shell.nix:18:7 called without required argument 'platinumpitanga', at /nix/store/j6spkp2a2sqd65db1sj9zzpgrfnkrwrp-source/pkgs/development/haskell-modules/make-package-set.nix:87:27

Here is the entire shell.nix I'm using. Please note I do realize I'll still need to 'override' the Haskell / GHC package - please ignore this - I'm just hoping I need to figure out how to reference the external github package for now.

{
  nixpkgs ? import <nixpkgs> {}
, compiler ? "default"
, doBenchmark ? false
, sources ? import ./nix/sources.nix
}:

let

  niv = import sources.nixpkgs {
    overlays = [
      (_ : _ : { niv = import sources.niv {}; })
    ] ;
    config = {};
  };
  inherit (niv) pkgs;

  f = { mkDerivation, aeson, base, bytestring, containers, hpack
      , influxdb, lens, platinumpitanga, pretty-simple, split, stdenv
      , stm, string-conversions, text, time, vector
      }:
      mkDerivation {
        pname = "UraniumZuluGooseberry";
        version = "0.1.0.0";
        src = ./.;
        isLibrary = false;
        isExecutable = true;
        libraryToolDepends = [ hpack ];
        executableHaskellDepends = [
          aeson base bytestring containers influxdb lens platinumpitanga
          pretty-simple split stm string-conversions text time vector
        ];
        preConfigure = "hpack";
        license = stdenv.lib.licenses.bsd3;
      };

  haskellPackages = if compiler == "default"
                       then pkgs.haskellPackages
                       else pkgs.haskell.packages.${compiler};

  variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;

  drv = variant (haskellPackages.callPackage f {});

in

  if pkgs.lib.inNixShell then drv.env else drv

Upvotes: 4

Views: 986

Answers (2)

Chris Stryczynski
Chris Stryczynski

Reputation: 34001

The actual "nix derivation" seems to be sources.PlatinumPitanga for example. However one still needs to import sources.PlatinumPitanga {} to use it (instantiate it?) as a "package".

Upvotes: 0

Chris Stryczynski
Chris Stryczynski

Reputation: 34001

  niv = import sources.nixpkgs {
    overlays = [
      (_ : _ : {
        niv = import sources.niv {};
        platinumpitanga = niv.pkgs.haskellPackages.callCabal2nix "platinumpitanga"
          (sources.PlatinumPitanga) {} ;
      })
    ] ;
    config = {};
  };
  inherit (niv) pkgs;

I think the above is all that is needed (I've managed to go further with the nix-build at least).

Essentially sources.PlatinumPitanga - it's the name of the "repository".

Upvotes: 3

Related Questions