Only one Nixpkgs in a flake input can allow unfree

Hello! I am stuck!

I’ve been working on moving my configuration to a flake, and I’ve used the 20.03 and master branches as inputs for packages. I can successfully build a configuration that uses unstable packages - but ONLY when they are ‘free’

I’m stuck because I’ve allowed unfree packages from my 20.03 branch. Why does the config not apply everywhere?

I’m using the generic configuration.nix - inside the package listing, I have tried importing GNU Hello as my control, and VSCode as my test.

vscode # always works
# unstable.vscode # never works
# hello # always works
unstable.hello # always works

my flake.nix is as follows:

  inputs = {
    nixpkgs-unstable.url = "github:nixos/nixpkgs/master";
    nixpkgs.url = "github:nixos/nixpkgs/nixos-20.03";

  outputs = {self, nixpkgs, nixpkgs-unstable}:
    unstableOverlay = final: prev: {
      unstable = nixpkgs-unstable.legacyPackages."x86_64-linux";
      nixpkgs-unstable.config.allowUnfree = true; # snake eyes!
  in  {
    nixosConfigurations.MyComputer = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [ 
          nixpkgs = {
            overlays = [ unstableOverlay ];
            config.allowUnfree = true; # this is the only allowUnfree that's actually doing anything


I would expect that somewhere I can provide config.allowUnfree=true; to get unfree packages from 20.03 and master, but I always get this error.

Package ‘vscode-1.48.2’ in /nix/store/r14s33j91sbz7kc511hxxaxpnzcmv86d-source/pkgs/applications/editors/vscode/vscode.nix:40 has an unfree license (‘unfree’), 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.

(use '--show-trace' to show detailed location information)

I’ve also tried adding nixpkgs.config.allowUnfree = true; to the configuration.nix but I have the same issue.

I have tried adding unstable.config.allowUnfree = true; but I suspect this is nonesense, Nix did not appreciate me trying. (option does not exist)

I’ve also triple checked my ~/.config/nixpkgs/config.nix file, and event copied it into /root/.config/nix/ just for fun.

Any advice? I suppose I can just cast 20.03 into the fire but I feel like a real solution must exist somewhere :frowning:

1 Like

I think this should work:

unstableOverlay = final: prev: {
  unstable = import nixpkgs-unstable {
    system = "x86_64-linux";
    config.allowUnfree = true;

That works! :pray: thank you so much :pray:

PS I was very tired that day, but I now realize that I could have expanded more upon my answer. I’m relatively new to Nix so this was an insightful question for me as well, so I thought I’d share how I came to my answer :slight_smile:

I first looked at nixpkgs’ flake.nix, where I found that it does a import ./. { inherit system; }, while iterating over all valid systems. import ./. imports the default.nix in the same directory, of course.

I then looked at default.nix, which basically does an import pkgs/top-level/impure.nix, and calls it with the config argument (and others) it was given. From this point on it was all familiar to me. Combined with my understanding (assumptions, really) of flakes, that a flake evaluates to it’s path in the nix store, I came to the conclusion that

import nixpkgs-unstable { config = ... }

would give you the desired result. Hope this helps in any way!