nixpkgs.config: Add allowUnfreePackages option (#1742)

This commit is contained in:
Sam 2026-05-17 16:55:09 +00:00 committed by GitHub
commit 56c666e108
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 51 additions and 2 deletions

View file

@ -17,10 +17,13 @@ let
mergeConfig = mergeConfig =
lhs_: rhs_: lhs_: rhs_:
let let
lhs = optCall lhs_ { inherit pkgs; }; lhs = optCall lhs_ { inherit lib pkgs; };
rhs = optCall rhs_ { inherit pkgs; }; rhs = optCall rhs_ { inherit lib pkgs; };
in in
lib.recursiveUpdate lhs rhs lib.recursiveUpdate lhs rhs
// lib.optionalAttrs (lhs ? allowUnfreePackages) {
allowUnfreePackages = lhs.allowUnfreePackages ++ (lib.attrByPath [ "allowUnfreePackages" ] [ ] rhs);
}
// lib.optionalAttrs (lhs ? packageOverrides) { // lib.optionalAttrs (lhs ? packageOverrides) {
packageOverrides = packageOverrides =
pkgs: pkgs:

View file

@ -93,6 +93,7 @@ in {
tests.networking-networkservices-no-dhcp-client-id = makeTest ./tests/networking-networkservices-no-dhcp-client-id.nix; tests.networking-networkservices-no-dhcp-client-id = makeTest ./tests/networking-networkservices-no-dhcp-client-id.nix;
tests.nix-enable = makeTest ./tests/nix-enable.nix; tests.nix-enable = makeTest ./tests/nix-enable.nix;
tests.nixpkgs-overlays = makeTest ./tests/nixpkgs-overlays.nix; tests.nixpkgs-overlays = makeTest ./tests/nixpkgs-overlays.nix;
tests.nixpkgs-config-allow-unfree = makeTest ./tests/nixpkgs-config-allow-unfree.nix;
tests.programs-gnupg = makeTest ./tests/programs-gnupg.nix; tests.programs-gnupg = makeTest ./tests/programs-gnupg.nix;
tests.programs-ssh = makeTest ./tests/programs-ssh.nix; tests.programs-ssh = makeTest ./tests/programs-ssh.nix;
tests.programs-tmux = makeTest ./tests/programs-tmux.nix; tests.programs-tmux = makeTest ./tests/programs-tmux.nix;

View file

@ -0,0 +1,45 @@
# Check that nixpkgs.config.allowUnfreePackages is merged correctly
# run with: nix-build release.nix -A tests.nixpkgs-config-allow-unfree
{
config,
lib,
pkgs,
...
}:
{
# Module 1: Define some unfree packages
nixpkgs.config.allowUnfreePackages = [
"vscode"
"slack"
];
# Module 2: Define more unfree packages (simulating multiple modules)
# In a real scenario, this would be in a separate file
imports = [
(
{ config, ... }:
{
nixpkgs.config.allowUnfreePackages = [
"zoom"
"discord"
];
}
)
];
test = ''
echo checking allowUnfreePackages merging >&2
# Verify that all packages from both modules are present
expected_packages=("discord" "slack" "vscode" "zoom")
actual_packages=(${builtins.toString (builtins.sort builtins.lessThan config.nixpkgs.config.allowUnfreePackages)})
for pkg in "''${expected_packages[@]}"; do
if [[ ! " ''${actual_packages[@]} " =~ " $pkg " ]]; then
echo "ERROR: Expected package '$pkg' not found in allowUnfreePackages" >&2
exit 1
fi
done
'';
}