I'm trying to enable allow "unfree" packages, either globally or per-package, when using MyNixOS (excellent Flake configuration app for Nix) with Nix Flakes on Mac OS.
When trying to install any unfree package after the following Flake update and Darwin rebuild command:
cd ~/.nix/mynixos-nix-darwin-loader;
nix flake update;
darwin-rebuild switch --show-trace --flake .#name_of_my_config'
I get the following help message, which isn't very helpful because it doesn't consider the Flake scenario:
error: Package ‘ec2-api-tools-1.7.5.1’ in /nix/store/${hash}-source/pkgs/tools/virtualization/e
c2-api-tools/default.nix:36 has an unfree license (‘amazonsl’), 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) [
"ec2-api-tools"
];
}
c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
{ allowUnfree = true; }
to ~/.config/nixpkgs/config.nix.
Using MyNixOS downloads the following Flake file, and
/nix/store/${hash}-source/homeConfigurations/my_flake_name.nix
:
{ inputs, ... }@flakeContext:
let
homeModule = { config, lib, pkgs, ... }: {
config = {
home = {
packages = [
ec2-api-tools
# ... (more packages)
];
stateVersion = "23.11";
};
nixpkgs = {
config = {
allowUnfree = true;
# allowUnfreePredicate = (_: true);
allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
"ec2-api-tools"
];
};
};
# ... (the rest of the file)
Which results in a configuration path for the allowUnfreePredicate
setting: homeModule.config.nixpkgs.config.allowUnfreePredicate
. Does that seem correct?
This configuration seems to make no difference, and installing unfree packages always results in the same error.
Exactly what needs to be done to allow unfree packages in each of these distinct scenarios?
- NixOS
- Nix
- Nix with Flakes
- Nix with Flakes and Home Manager
(Please edit the list or let me know if it doesn't make sense)
The advice from the following web pages didn't seem to apply, or I couldn't figure out how to apply it:
Setting
nixpkgs.config
in ahomeModule
wouldn't make sense here; as you appear to be usingnix-darwin
with HM as a system module, you'll have to configurenixpkgs
at the system level, not within an HM module.