Flakes with unfree licenses

tldr: I can’t build flakes that depend on allowUnfree = true

Hello. Not sure if it relates to nix or nixpkgs, so posting here again.

For context, I’m trying to set up a development environment for my project using nix with flakes. In particular, I intend to use the latter for 1) pinning versions of dependencies, 2) composing projects from different repos. Previously I used niv in this project.

One of the dependencies I need is nixpkgs#python3Packages.pytorch-bin which has an unfree license. The combination of niv and nix-shell/nix-build respected the allowUnfree = true; in my ~/.config/nixpkgs/config.nix and worked fine. This is not so for flake-based nix build which can’t rely on my system’s configuration and instead ensure hermetic builds. So, nix build aborts with an error message about allowUnfree. Further, running nix build nixpkgs#python3Packages.pytorch-bin shuts down in the same manner.

From this point, however, I am not sure what am I supposed to do, as my goal is to describe

  • a "flake with an output that only supports systems with allowUnfree = true"
  • a "flake that would refuse to build on systems with allowUnfree = false"
  • a "flake that depends on nixpkgs with config.allowUnfree = true"?
    • in particular, taking inputs.nixpkgs.url = "nixpkgs/nixos-20.09" input and overriding allowUnfree in its outputs wouldn’t work because some of inputs’ attributes are already evaluated with allowUnfree = false

I couldn’t find any options on marking flakes/flake outputs as unfree and atm couldn’t nix build my project. It seems like allowUnfree should really be a part of system.

Aside: It’s also interesting that flakes don’t seem to have a notion of a license… Since flakes’ purpose is composition of different projects (I am still unsure I am not misunderstanding the goals and not taking the desired for reality) they probably relate to licensing and compatibility of licenses

Related:

Thanks

2 Likes
2 Likes

You can input nixpkgs with flake = false and then call it with config.allowUnfree = true. For example:

{ 
  description = "nonfree nixpkgs flake example";
  inputs.nixpkgs = {
    url = "https://nixos.org/channels/nixos-20.09/nixexprs.tar.xz";
  };
  outputs = { self, nixpkgs }: {
    defaultPackage.x86_64-linux =
      with import "${nixpkgs}" {
        system = "x86_64-linux";
        config.allowUnfree = true;
      };
      spotify;
  };
}

This seems to work well for my purposes. I don’t know if there is a better way, I’ve only recently started using flakes.

2 Likes

A small correction, passing flake = false is not necessary. If nixpkgs.legacyPackages is not being used then it won’t be instantiated (thanks to Nix being lazy). What is required is the part that creates a new instance of nixpkgs.

Flake inputs are an attrset that also behaves like a string. This is why it’s possible to import nixpkgs {} while also accessing keys under it.

4 Likes