Hello everyone!
(Sorry in advance for the long post, maybe it’s enough to read the TL;DR.)
In a reply to one of my previous posts @TLATER recommended to change the way I handle my pkgs configuration in my flake.nix
and also suggested to use allowUnfreePredicate
(mentioned in the Manual and the Wiki) for packages that need it.
Today I tried to implement the suggestions but failed.
TL;DR
My issue boils down to: where and how do I use allowUnfreePredicate
precisely? For example, one of the unfree applications that I use is installed with an option programs.<app_name>.enable = true
and another one is installed as part of the users.<username>.packages = [ ]
list in a separate file called users.nix
.
By trial and error, I know just doing the following doesn’t work: (EDIT: It works! It turns out the mistake was something else. Read the rest of this thread if your’re interested.)
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
"app_1"
];
programs.app_1.enable = true;
What am I doing wrong?
MORE IN-DEPTH EXPLANATION
So far, my flake.nix
looked like this:
{
description = "NixOS System Flake";
outputs = inputs@{ self, nixpkgs, nixpkgs-unstable, nixos-hardware, ... }:
let
/* ---- GLOBAL SETTINGS ---- */
system = "x86_64-linux";
desktop = "gnome";
/* ---- PKGS ---- */
pkgs = import nixpkgs {
inherit system;
config = { allowUnfree = true; };
};
pkgs-unstable = import nixpkgs-unstable {
inherit system;
config = { allowUnfree = true; };
};
in {
nixosConfigurations = {
"Moon-Presence" = nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = { inherit desktop pkgs pkgs-unstable; };
modules = [
./hosts/Moon-Presence/configuration.nix
nixos-hardware.nixosModules.dell-xps-13-9310
];
};
"Oceiros" = nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = { inherit desktop pkgs pkgs-unstable; };
modules = [
./hosts/Oceiros/configuration.nix
];
};
};
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
};
}
The configuration.nix
in turn imports several other nix files, specific to the host machine.
Now, I changed the PKGS section in the let binding to:
pkgs = nixpkgs.legacyPackages.${system};
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
Of course, when I try to rebuild the system with this change Nix complains about the unfree license of some programs and refuses to continue.
Now the question is, how do I pass allowUnfreePredicate
correctly to these programs?
Here are two examples: One of the applications is 1Password, which is included in my configuration like this
programs._1password-gui = {
enable = true;
polkitPolicyOwners = [ "<username>" ];
package = pkgs-unstable._1password-gui;
};
Another application is Spotify, which is declared in a separate users.nix
file that gets imported to configuration.nix
and which contains the line:
users.users.<username>.packages = with pkgs; [ spotify ];
In both cases, just prepending
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
"1password"
"spotify"
];
doesn’t work. So, what do I need to do here? As always, thanks a lot for your help! (And sorry if I missed any obvious solutions.)