mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-10-03 21:40:12 +00:00
By doing this, we can cache the rest of the file, including the import of problems.nix. This allows genCheckProblems to be cached on every bootstrapping stage, and not re-called each time.
152 lines
3.6 KiB
Nix
152 lines
3.6 KiB
Nix
# Execute with
|
|
# nix-build -A nixosTests.nixpkgs-config-allow-unfree-packages-and-predicate --show-trace
|
|
#
|
|
# This test exercises the interaction between:
|
|
#
|
|
# - nixos/modules/misc/nixpkgs.nix (config merging, esp. allowUnfreePackages)
|
|
# - pkgs/stdenv/generic/check-meta.nix (allowUnfreePredicate logic)
|
|
#
|
|
# It checks how:
|
|
#
|
|
# * config.allowUnfreePackages
|
|
# * config.allowUnfreePredicate
|
|
#
|
|
# interact to determine whether unfree packages are allowed.
|
|
{
|
|
lib,
|
|
pkgs,
|
|
}:
|
|
|
|
let
|
|
inherit (lib)
|
|
assertMsg
|
|
generators
|
|
licenses
|
|
nameValuePair
|
|
recurseIntoAttrs
|
|
replaceString
|
|
;
|
|
|
|
mkPkg = name: license: {
|
|
pname = name;
|
|
version = "1.0";
|
|
meta.license = license;
|
|
};
|
|
|
|
assertValidity =
|
|
{
|
|
nixpkgsConfig,
|
|
pkg,
|
|
expected ? true,
|
|
}:
|
|
let
|
|
testPkgs = import ../../.. {
|
|
system = pkgs.stdenv.hostPlatform.system;
|
|
config = nixpkgsConfig;
|
|
};
|
|
checkMeta = testPkgs.callPackage ./check-meta.nix { };
|
|
tryEval = expression: builtins.tryEval (builtins.deepSeq expression expression);
|
|
actual = tryEval (
|
|
checkMeta.assertValidity pkgs.stdenv.hostPlatform {
|
|
meta = pkg.meta;
|
|
attrs = pkg;
|
|
}
|
|
);
|
|
toPretty = generators.toPretty { };
|
|
in
|
|
assertMsg (actual.success == expected) ''
|
|
Expected validity of package '${lib.getName pkg}' with unfree license
|
|
'${licenses.toSPDX pkg.meta.license}' to be ${toPretty expected}, but got
|
|
${toPretty actual}
|
|
with config:
|
|
${toPretty nixpkgsConfig}
|
|
'';
|
|
|
|
runAssertions = assertions: lib.deepSeq assertions "";
|
|
|
|
mkTests = mkUnfreePkg: {
|
|
allowOnlyFreePackagesByDefault = assertValidity {
|
|
nixpkgsConfig = { };
|
|
pkg = mkUnfreePkg "forbidden";
|
|
expected = false;
|
|
};
|
|
|
|
allowAllUnfreePackages = assertValidity {
|
|
nixpkgsConfig = {
|
|
allowUnfree = true;
|
|
};
|
|
pkg = mkUnfreePkg "allowed";
|
|
};
|
|
|
|
allowUnfreePackagesWithPredicate =
|
|
let
|
|
nixpkgsConfig = {
|
|
allowUnfreePredicate = pkg: lib.getName pkg == "allowed-by-predicate";
|
|
};
|
|
in
|
|
[
|
|
(assertValidity {
|
|
inherit nixpkgsConfig;
|
|
pkg = mkUnfreePkg "allowed-by-predicate";
|
|
})
|
|
(assertValidity {
|
|
inherit nixpkgsConfig;
|
|
pkg = mkUnfreePkg "allowed-by-nothing";
|
|
expected = false;
|
|
})
|
|
];
|
|
|
|
allowUnfreeWithPackages = runAssertions [
|
|
(assertValidity {
|
|
nixpkgsConfig = {
|
|
allowUnfreePackages = [ "unfree" ];
|
|
};
|
|
pkg = mkUnfreePkg "unfree";
|
|
expected = true;
|
|
})
|
|
];
|
|
|
|
allowUnfreePackagesOrPredicate =
|
|
let
|
|
nixpkgsConfig = {
|
|
allowUnfreePackages = [ "allowed-by-packages" ];
|
|
allowUnfreePredicate = pkg: lib.getName pkg == "allowed-by-predicate";
|
|
};
|
|
in
|
|
runAssertions [
|
|
(assertValidity {
|
|
inherit nixpkgsConfig;
|
|
pkg = mkUnfreePkg "allowed-by-packages";
|
|
})
|
|
(assertValidity {
|
|
inherit nixpkgsConfig;
|
|
pkg = mkUnfreePkg "allowed-by-predicate";
|
|
})
|
|
(assertValidity {
|
|
inherit nixpkgsConfig;
|
|
pkg = mkUnfreePkg "forbidden";
|
|
expected = false;
|
|
})
|
|
];
|
|
};
|
|
|
|
unfreeLicenses = [
|
|
licenses.unfree
|
|
(licenses.AND [
|
|
licenses.free
|
|
licenses.unfree
|
|
])
|
|
];
|
|
in
|
|
|
|
recurseIntoAttrs (
|
|
builtins.listToAttrs (
|
|
map (
|
|
license:
|
|
nameValuePair (replaceString " " "-" (licenses.toSPDX license)) (
|
|
recurseIntoAttrs (mkTests (name: mkPkg name license))
|
|
)
|
|
) unfreeLicenses
|
|
)
|
|
)
|