Build an environment containing Python packages

I’m trying to build an environment to manage my packages declaratively. Following the instructions in the manual, I’ve put the following lines in config.nix file:

{
  packageOverrides = pkgs: with pkgs; {
    python3Env = python3.withPackages (ps: with ps;
      [
        matplotlib
        numpy
        scipy
      ]
    );
    myPackages = pkgs.buildEnv {
      name = "my-packages";
      paths = [
        coreutils
        emacs
        python3Env # this does not work, why?
      ];
    };
  };
}

When python3Env is included in the path list, I get the following error:

% nix-env -iA myPackages
replacing old 'my-packages'
installing 'my-packages'
error: undefined variable 'python3Env' at /Users/smaret/.config/nixpkgs/config.nix:17:9
(use '--show-trace' to show detailed location information)

How can I fix that?

Use the rec keyword when defining the attrset.

{
  packageOverrides = pkgs: with pkgs; rec { … };
}
2 Likes