Search code examples
nixnixosnixpkgs

glpk and pcre not found (NIXOS)


I am trying to build my own nix-shell environment in my NixOS. I have 2 .nix file, default.nix and shell.nix, here's the configuration:

default.nix:

{ stdenv, haskellngPackages}:

let
  env = haskellngPackages (p: with p; [
        aeson
        bytestring
        conduit
        snap
        ghcjs
        text
        wai
        warp
        yaml
        haskell.packages.lts-4_01.ghc
        ]);

in
  stdenv.mkDerivation {
  name = "RiziLab";

buildInputs = [
  glpk
  pcre
  env
];

    STACK_IN_NIX_EXTRA_ARGS
       = " --extra-lib-dirs=${glpk}/lib"
       + " --extra-include-dirs=${pglpk}/include"
       + " --extra-lib-dirs=${pcre}/lib"
       + " --extra-include-dirs=${pcre}/include"
    ;
}

shell.nix:

{ pkgs ? (import <nixpkgs> {} ) }:

(import ./default.nix) {
  stdenv  = pkgs.stdenv;
  haskellngPackages = pkgs.haskellngPackages;
}

but when I do nix-shell, i got this error:

error: undefined variable ‘glpk’

from what I understand, the default.nix is only a function which will be called by the shell.nix, cmiiw. The question is:

  1. Is there any error in my code?
  2. I have used either {nixpkgs ? (import <nixpkgs> {} ) } and {pkgs ? (import <nixpkgs> {})} but still got the same error, is there any different between these two?
  3. is it okay to exclude ghcwithPackages?

Solution

  • glpk not being defined in default.nix is the problem.
    glpk path is pkgs.glpk but there is no pkgs in default.nix scope and glpk is not passed as a parameter to the function.

    Also, there is no need to have 2 separate files, it is possible to group the whole in one file:

    { nixpkgs ? import <nixpkgs> {}, compiler ? "lts-4_1" }:
    let
      inherit (nixpkgs) pkgs;
      ghc = pkgs.haskell.packages.${compiler}.ghcWithPackages (ps: with ps; [
              aeson
              bytestring
              conduit
              snap
              # ghcjs # not a package but a compiler
              text
              wai
              warp
              yaml
            ]);
    in
    pkgs.stdenv.mkDerivation {
      name = "RiziLab";
      buildInputs = with pkgs; [ ghc glpk pcre ];
      shellHook = "eval $(egrep ^export ${ghc}/bin/ghc)";
      STACK_IN_NIX_EXTRA_ARGS = with pkgs; 
          " --extra-lib-dirs=${glpk}/lib"
        + " --extra-include-dirs=${glpk}/include"
        + " --extra-lib-dirs=${pcre}/lib"
        + " --extra-include-dirs=${pcre}/include"
      ;
    }
    

    You can learn more about using haskell in nix in the Nixpkgs manual.