Announcing nixpkgs-unfree

Tags
Project
Updated at
Feb 4, 2022 5:16 PM
Published at
February 4, 2022

Recently I was saying that we should avoid creating too many instances of nixpkgs. Either accept an argument or use the flake follows feature:

1000 instances of nixpkgs

There is just one problem with this claim; what if you need to access unfree packages? For example, try running:

$ nix run nixpkgs#slack

error: Package ā€˜slack-4.22.0ā€™ in /nix/store/fbcgjqs34vllzzppa1y213fbxx01sxn7-source/pkgs/applications/networking/instant-messengers/slack/default.nix:83 has an unfree license (ā€˜unfreeā€™), refusing to evaluate.

       a) To temporarily allow unfree packages, you can use an environment variable
          for a single invocation of the nix tools.

            $ export NIXPKGS_ALLOW_UNFREE=1

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

       Alternatively you can configure a predicate to allow specific packages:
         { nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
             "slack"
           ];
         }

       c) 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)

Oops!

This whole error message is misleading. All the solutions proposed donā€™t work when using Flakes because Flakes evaluation is pure and doesnā€™t take your environment variables or config into account.

In order to fix that problem, allow me to introduce a new project:

Itā€™s a small wrapper to nixpkgs with allowUnfree = true; enabled. I know I said not to create new instances of nixpkgs, but thatā€™s the last one I promise šŸ™‚

So now with that, you can run:

$ nix run --no-write-lock-file github:numtide/nixpkgs-unfree#slack

Itā€™s also usable as a flake, so you can point nixpkgs to it:

{
  inputs.nixpkgs.url = "github:numtide/nixpkgs-unfree";
}

In the future, I also want to also keep the channels synchronized with nixpkgs so you can run nix run github:numtide/nixpkgs-unfree/<channel>. And potentially provide a binary cache for it.

Thatā€™s it for now, have a great weekend!

Discussion

If you want to comment on the article, head over to the NixOS Discourse:

Addendum: how many instances of allowUnfree are there on GitHub?

Thanks to @tazjin for pointing me to a more usable code search: https://sourcegraph.com/search?q=context:global+file:flake.nix+allowUnfree&patternType=literal

At the time of writing, there are 218 results.