Pytorch derivation fail: dependency has an unfree license

Hi,

I have this simple shell.nix:

 with import <nixpkgs> {};

let
  python = python37;
in
pkgs.mkShell rec {
  allowUnfree = true;
  name = "pytorch-example";
  buildInputs = with pkgs.python37Packages; [
    pytorch
  ];
  src = null;
}                     

When running nix-shell I get:

❯ nix-shell --show-trace
error: while evaluating the attribute 'buildInputs' of the derivation 'pytorch-example' at /home/corentin/test/shell.nix:8:3:
while evaluating the attribute 'dev.outPath' at /nix/store/p0j9f6zpd68x90bx3gymxb4nkm9igzdj-nixos-20.03pre211015.8539d5f48f9/nixos/lib/customisation.nix:151:13:
while evaluating the attribute 'NIX_CFLAGS_COMPILE' of the derivation 'python3.7-pytorch-1.2.0' at /nix/store/p0j9f6zpd68x90bx3gymxb4nkm9igzdj-nixos-20.03pre211015.8539d5f48f9/nixos/pkgs/development/interpreters/python/mk-python-derivation.nix:105:3:
while evaluating 'optionals' at /nix/store/p0j9f6zpd68x90bx3gymxb4nkm9igzdj-nixos-20.03pre211015.8539d5f48f9/nixos/lib/lists.nix:270:5, called from /nix/store/p0j9f6zpd68x90bx3gymxb4nkm9igzdj-nixos-20.03pre211015.8539d5f48f9/nixos/pkgs/development/python-modules/pytorch/default.nix:168:24:
while evaluating the attribute 'handled' at /nix/store/p0j9f6zpd68x90bx3gymxb4nkm9igzdj-nixos-20.03pre211015.8539d5f48f9/nixos/pkgs/stdenv/generic/check-meta.nix:251:7:
while evaluating 'handleEvalIssue' at /nix/store/p0j9f6zpd68x90bx3gymxb4nkm9igzdj-nixos-20.03pre211015.8539d5f48f9/nixos/pkgs/stdenv/generic/check-meta.nix:147:38, called from /nix/store/p0j9f6zpd68x90bx3gymxb4nkm9igzdj-nixos-20.03pre211015.8539d5f48f9/nixos/pkgs/stdenv/generic/check-meta.nix:252:14:
Package ‘mkl-2019.5.281’ in /nix/store/p0j9f6zpd68x90bx3gymxb4nkm9igzdj-nixos-20.03pre211015.8539d5f48f9/nixos/pkgs/development/libraries/science/math/mkl/default.nix:132 has an unfree license (‘issl’), refusing to evaluate.

a) For `nixos-rebuild` you can set
  { nixpkgs.config.allowUnfree = true; }
in configuration.nix to override this.

b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowUnfree = true; }
to ~/.config/nixpkgs/config.nix.

I do have allowUnfree = true; at the system level, and in the shell.nix. I can workaround the issue with NIXPKGS_ALLOW_UNFREE=1 nix-shell. However I guess the appropriate fix is to tweak the mkl-2019.5.281 derivation with a let construct, but I’m not sure how to do that.

Edit: I should mention that I’m using the unstable channel, so maybe that’s why it’s broken.

You can’t use allowUnfree at the derivation level as far as I understand, but instead you need to configure the imported nixpkgs.

with import <nixpkgs> { config = { allowUnfree = true; }; };

Alternatively, you can simply provide that configuration userwise as suggested by the output and create a ~/.config/nixpkgs/config.nix in which you enable the allowUnfree for everything your user does.

2 Likes

Instead of allowUnfree, you can also be a bit more restrictive with allowUnfreePredicate. Here is mine:

allowUnfreePredicate = (pkg: elem (pkg.pname or (builtins.parseDrvName pkg.name).name) [
  # unfree whitelist
  "spotify"
  "steam-runtime" # not actually used, but needed by steam-run
]);
2 Likes