Using non-free libraries in flakes

Flakes evaluations are pure and therefor don’t source configuration from the user’s home.

The issue is that when using nixpkgs.legacyPackages.x86_64-linux.mkl, that instance of nixpkgs has already been configured. Instead, try importing and constructing another instance of nixpkgs with allowUnfree = true; in the config.

Before:

{
  description = "Flake utils demo";

  inputs.flake-utils.url = "github:numtide/flake-utils";

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let pkgs = nixpkgs.legacyPackages.${system}; in
      {
        defaultPackage = pkgs.mkl;
      }
    );
}

After:

{
  description = "Flake utils demo";

  inputs.flake-utils.url = "github:numtide/flake-utils";

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          config = { allowUnfree = true; };
        };
      in 
      {
        defaultPackage = pkgs.mkl;
      }
    );
}
9 Likes