Override meta.licenses of a package with Nixpkgs overlays

I don’t want to allow unfree packages in general but only allow a whitelist, so instead of using nixpkgs.config.allowUnfree = true I used to fork Nixpkgs and patch the licenses in question from unfree to free. It’s a hack, but it works.

Now I want to replicate that behaviour with overlays. My current approach is

  nixpkgs.overlays = [
    (self: super: {
      unifiLTS = self.lib.overrideDerivation super.unifiLTS (attrs: rec{
        license = self.stdenv.lib.licenses.free;
      });
    }
    )
  ];

but building the system still results in

error: Package ‘unifi-controller-5.6.39’ in /home/justin/nixpkgs/pkgs/servers/unifi/default.nix:35 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.

What am I doing wrong?

1 Like

Not a direct answer, but are you aware of the allowUnfreePredicate option? Nixpkgs 23.11 manual | Nix & NixOS

1 Like

Direct answer (sorry for double post!): you’ll want to use overrideAttrs, because overrideDerivation needs to evaluate the original derivation first. Since overrideAttrs’s introduction, there are very few cases where overrideDerivation is the right thing to use.

2 Likes

Thanks alot!

The allowUnfreePredicate is exactly what I was looking for. The fact that that overrideAttrs should be prefered over overrideDerivation is also good to know.

1 Like