Cant get unfree packages to install on nixos using nix-shell

I’m trying to install a specific version of mongodb using this command nix-shell -p mongodb-4_4 but get the below error.

error: Package ‘mongodb-4.4.13’ in /nix/store/q3w6aldk8khr1f6vd050r8ambymz43x4-nixos-22.05/nixos/pkgs/servers/nosql/mongodb/mongodb.nix:133 has an unfree license (‘SSPL’), 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

        Note: For `nix shell`, `nix build`, `nix develop` or any other Nix 2.4+
        (Flake) command, `--impure` must be passed in order to read this
        environment variable.

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

       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)

I have set nixpkgs.config.allowUnfree = true; in both my configuration.nix and also in my home.nix yet I still get this error.

Is there something I am missing here?

you need to do part C

c) For nix-env, nix-build, nix-shell or any other Nix command you can add
{ allowUnfree = true; }
to ~/.config/nixpkgs/config.nix

This is required even if you have it added to your configuration.nix file

Thanks for the reply!
This file does not exist on my system, should I create it?


mkdir -p ~/.config/nixpkgs
echo “{ allowUnfree = true; }” >> ~/.config/nixpkgs/config.nix

Thanks this is working thank you so much!!!
I am surprised that I need to create a config file that is external to my configuration.nix as I thought the whole point of nixos is to have your configuration all in one place. Do you know what the reasoning is behind this?

honestly I’m not sure, I’m fairly new to nixos. I imagine home-manager might be able to set this up for you, but I haven’t yet gotten that far into my configuration yet.

1 Like