From 69b558415905ef2468ae556f2318ee853d797bbb Mon Sep 17 00:00:00 2001 From: AkechiShiro <14914796+AkechiShiro@users.noreply.github.com> Date: Thu, 29 Aug 2024 22:49:17 +0200 Subject: [PATCH] RFC 127: Add implementation tests * Also fix merge conflicts * Make sure that performance PR is conserved * Use RunCommand instead of alias RunCommandNoCC * Add enum types to meta-types.nix and use them for problemTypes * Nixfmt (excepted check-meta.nix) * "import" elem * Remove dead code --- pkgs/stdenv/generic/check-meta.nix | 86 ++++++++----------- pkgs/stdenv/generic/meta-types.nix | 84 ++++++++++++------ pkgs/stdenv/generic/problems.nix | 53 +++++++----- .../default.nix | 23 +++++ .../expected-stderr | 38 ++++++++ .../deprecated-and-removal-error/default.nix | 22 +++++ .../expected-stderr | 35 ++++++++ .../cases/deprecated-error/default.nix | 20 +++++ .../cases/deprecated-error/expected-stderr | 32 +++++++ .../cases/deprecated-ignore/default.nix | 18 ++++ .../cases/deprecated-ignore/expected-stderr | 1 + .../cases/deprecated-warn/default.nix | 18 ++++ .../cases/deprecated-warn/expected-stderr | 2 + .../cases/invalid-kind-error/default.nix | 15 ++++ .../cases/invalid-kind-error/expected-stderr | 7 ++ .../default.nix | 23 +++++ .../expected-stderr | 2 + .../default.nix | 19 ++++ .../expected-stderr | 2 + .../cases/maintainerless-error/default.nix | 17 ++++ .../maintainerless-error/expected-stderr | 32 +++++++ .../cases/maintainerless-ignore/default.nix | 17 ++++ .../maintainerless-ignore/expected-stderr | 1 + .../cases/maintainerless-warn/default.nix | 17 ++++ .../cases/maintainerless-warn/expected-stderr | 2 + .../problems/cases/no-problems/default.nix | 15 ++++ .../cases/no-problems/expected-stderr | 1 + .../problems/cases/removal-error/default.nix | 15 ++++ .../cases/removal-error/expected-stderr | 32 +++++++ .../problems/cases/removal-ignore/default.nix | 17 ++++ .../cases/removal-ignore/expected-stderr | 1 + .../cases/removal-twice-error/default.nix | 21 +++++ .../cases/removal-twice-error/expected-stderr | 6 ++ .../problems/cases/removal-warn/default.nix | 18 ++++ .../cases/removal-warn/expected-stderr | 2 + pkgs/test/problems/default.nix | 10 +-- 36 files changed, 616 insertions(+), 108 deletions(-) create mode 100644 pkgs/test/problems/cases/deprecated-and-removal-and-maintainerless-error/default.nix create mode 100644 pkgs/test/problems/cases/deprecated-and-removal-and-maintainerless-error/expected-stderr create mode 100644 pkgs/test/problems/cases/deprecated-and-removal-error/default.nix create mode 100644 pkgs/test/problems/cases/deprecated-and-removal-error/expected-stderr create mode 100644 pkgs/test/problems/cases/deprecated-error/default.nix create mode 100644 pkgs/test/problems/cases/deprecated-error/expected-stderr create mode 100644 pkgs/test/problems/cases/deprecated-ignore/default.nix create mode 100644 pkgs/test/problems/cases/deprecated-ignore/expected-stderr create mode 100644 pkgs/test/problems/cases/deprecated-warn/default.nix create mode 100644 pkgs/test/problems/cases/deprecated-warn/expected-stderr create mode 100644 pkgs/test/problems/cases/invalid-kind-error/default.nix create mode 100644 pkgs/test/problems/cases/invalid-kind-error/expected-stderr create mode 100644 pkgs/test/problems/cases/maintainerless-and-removal-and-deprecated-warn/default.nix create mode 100644 pkgs/test/problems/cases/maintainerless-and-removal-and-deprecated-warn/expected-stderr create mode 100644 pkgs/test/problems/cases/maintainerless-and-removal-warn/default.nix create mode 100644 pkgs/test/problems/cases/maintainerless-and-removal-warn/expected-stderr create mode 100644 pkgs/test/problems/cases/maintainerless-error/default.nix create mode 100644 pkgs/test/problems/cases/maintainerless-error/expected-stderr create mode 100644 pkgs/test/problems/cases/maintainerless-ignore/default.nix create mode 100644 pkgs/test/problems/cases/maintainerless-ignore/expected-stderr create mode 100644 pkgs/test/problems/cases/maintainerless-warn/default.nix create mode 100644 pkgs/test/problems/cases/maintainerless-warn/expected-stderr create mode 100644 pkgs/test/problems/cases/no-problems/default.nix create mode 100644 pkgs/test/problems/cases/no-problems/expected-stderr create mode 100644 pkgs/test/problems/cases/removal-error/default.nix create mode 100644 pkgs/test/problems/cases/removal-error/expected-stderr create mode 100644 pkgs/test/problems/cases/removal-ignore/default.nix create mode 100644 pkgs/test/problems/cases/removal-ignore/expected-stderr create mode 100644 pkgs/test/problems/cases/removal-twice-error/default.nix create mode 100644 pkgs/test/problems/cases/removal-twice-error/expected-stderr create mode 100644 pkgs/test/problems/cases/removal-warn/default.nix create mode 100644 pkgs/test/problems/cases/removal-warn/expected-stderr diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix index 12012043a0d79..537380724d382 100644 --- a/pkgs/stdenv/generic/check-meta.nix +++ b/pkgs/stdenv/generic/check-meta.nix @@ -353,19 +353,9 @@ let in builtins.trace msg true; - # Deep type-checking. Note that calling `type.check` is not enough: see `lib.mkOptionType`'s documentation. - # We don't include this in lib for now because this function is flawed: it accepts things like `mkIf true 42`. - typeCheck = type: value: let - merged = lib.mergeDefinitions [ ] type [ - { file = lib.unknownModule; inherit value; } - ]; - eval = builtins.tryEval (builtins.deepSeq merged.mergedValue null); - in eval.success; - - metaTypes = let types = import ./meta-types.nix { inherit lib; }; - inherit (types) str union int attrs attrsOf any listOf bool; + inherit (types) str union int attrs attrsOf any listOf bool enum; platforms = listOf (union [ str (attrsOf any) ]); # see lib.meta.platformMatch in { # These keys are documented @@ -404,8 +394,11 @@ let insecure = bool; # This is checked in more detail further down problems = attrsOf (attrsOf any); - # TODO: refactor once something like Profpatsch's types-simple will land - # This is currently dead code due to https://github.com/NixOS/nix/issues/2532 + problemTypes = { + kind = enum problemKindsManual; + message = str; + urls = listOf str; + }; tests = { name = "test"; verify = x: x == {} || ( # Accept {} for tests that are unsupported @@ -437,15 +430,8 @@ let badPlatforms = platforms; }; - # Type of a meta.problems.* value - problemTypes = with lib.types; { - # Only allow some problem kinds to be used here in `meta` - kind = enum problemKindsManual; - message = str; - urls = listOf str; - }; - - checkMetaAttr = let + # Check that a value matches a specific type. Returns an error message, or null if the check passed + checkMetaAttr = let # Map attrs directly to the verify function for performance metaTypes' = mapAttrs (_: t: t.verify) metaTypes; in k: v: @@ -458,15 +444,7 @@ let }" ] else [ "key 'meta.${k}' is unrecognized; expected one of: \n [${concatMapStringsSep ", " (x: "'${x}'") (attrNames metaTypes)}]" ]; - - checkMeta = - meta: - # Basic attribute checks - lib.optionals config.checkMeta ( - lib.remove null ( - lib.mapAttrsToList (checkMetaAttr "meta" metaTypes) meta - ) - ) + checkMeta = meta: optionals config.checkMeta (concatMap (attr: checkMetaAttr attr meta.${attr}) (attrNames meta) # Extended checks for problems, as they do not fit the module system ++ lib.optionals (meta ? problems) ( @@ -476,7 +454,7 @@ let (lib.mapAttrs (name: problem: { kind = name; } // problem)) (lib.mapAttrsToList ( name: problem: - lib.mapAttrsToList (checkMetaAttr "meta.problems.${name}" problemTypes) problem + lib.mapAttrsToList (checkMetaAttr "meta.problems.${name}" meta.problemTypes) problem )) (lib.concatLists) (lib.remove null) @@ -511,11 +489,11 @@ let (lib.mapAttrsToList ( kind: names: "keys [ ${ - concatMapStringsSep " " (name: "'meta.problems.${name}'") names + lib.concatMapStringsSep " " (name: "'meta.problems.${name}'") names } ] all have the same problem kind, which is not allowed for kind '${kind}'" )) ] - ); + )); checkOutputsToInstall = attrs: let expectedOutputs = attrs.meta.outputsToInstall or []; @@ -533,21 +511,24 @@ let # reason is one of "unfree", "blocklisted", "broken", "insecure", ... # !!! reason strings are hardcoded into OfBorg, make sure to keep them in sync # Along with a boolean flag for each reason - checkValidity = - let - validYes = { - valid = "yes"; - handled = true; - }; - in - attrs: + checkValidity = attrs: # Check meta attribute types first, to make sure it is always called even when there are other issues # Note that this is not a full type check and functions below still need to by careful about their inputs! - let - res = checkMeta (attrs.meta or {}); - in - if res != [] then - { valid = "no"; reason = "unknown-meta"; errormsg = "has an invalid meta attrset:${concatMapStrings (x: "\n - " + x) res}\n"; } + let res = checkMeta (attrs.meta or {}); in if res != [] then + { valid = "no"; reason = "unknown-meta"; errormsg = "has an invalid meta attrset:${lib.concatMapStrings (x: "\n - " + x) res}\n"; + unfree = false; nonSource = false; broken = false; unsupported = false; insecure = false; + } + else { + unfree = hasUnfreeLicense attrs; + nonSource = hasNonSourceProvenance attrs; + broken = isMarkedBroken attrs; + unsupported = hasUnsupportedPlatform attrs; + insecure = isMarkedInsecure attrs; + } // ( + # Check meta attribute types first, to make sure it is always called even when there are other issues + # Note that this is not a full type check and functions below still need to by careful about their inputs! + let res = checkMeta (attrs.meta or {}); in if res != [] then + { valid = "no"; reason = "unknown-meta"; errormsg = "has malformed metadata:${lib.concatMapStrings (x: "\n\t - " + x) res}"; } # --- Put checks that cannot be ignored here --- else if checkOutputsToInstall attrs then { valid = "no"; reason = "broken-outputs"; errormsg = "has invalid meta.outputsToInstall"; } @@ -559,10 +540,12 @@ let { valid = "no"; reason = "blocklisted"; errormsg = "has a blocklisted license (‘${showLicense attrs.meta.license}’)"; } else if hasDeniedNonSourceProvenance attrs then { valid = "no"; reason = "non-source"; errormsg = "contains elements not built from source (‘${showSourceType attrs.meta.sourceProvenance}’)"; } + + # --- Put checks that can be ignored here --- else if !allowBroken && attrs.meta.broken or false then { valid = "no"; reason = "broken"; errormsg = "is marked as broken"; } else if !allowUnsupportedSystem && hasUnsupportedPlatform attrs then - let toPretty' = toPretty { + let toPretty = lib.generators.toPretty { allowPrettyValues = true; indent = " "; }; @@ -570,8 +553,8 @@ let errormsg = '' is not available on the requested hostPlatform: hostPlatform.config = "${hostPlatform.config}" - package.meta.platforms = ${toPretty' (attrs.meta.platforms or [])} - package.meta.badPlatforms = ${toPretty' (attrs.meta.badPlatforms or [])} + package.meta.platforms = ${toPretty (attrs.meta.platforms or [])} + package.meta.badPlatforms = ${toPretty (attrs.meta.badPlatforms or [])} ''; } else if !(hasAllowedInsecure attrs) then @@ -602,8 +585,7 @@ let ; } # ----- - else validYes; - + else { valid = "yes"; }); # The meta attribute is passed in the resulting attribute set, # but it's not part of the actual derivation, i.e., it's not diff --git a/pkgs/stdenv/generic/meta-types.nix b/pkgs/stdenv/generic/meta-types.nix index ddbd1daca696e..d944f5dd2b32d 100644 --- a/pkgs/stdenv/generic/meta-types.nix +++ b/pkgs/stdenv/generic/meta-types.nix @@ -5,7 +5,20 @@ # TODO: add a method to the module system types # see https://github.com/NixOS/nixpkgs/pull/273935#issuecomment-1854173100 let - inherit (builtins) isString isInt isAttrs isList all any attrValues isFunction isBool concatStringsSep isFloat; + inherit (builtins) + isString + isInt + isAttrs + isList + all + any + attrValues + isFunction + isBool + concatStringsSep + isFloat + elem + ; isTypeDef = t: isAttrs t && t ? name && isString t.name && t ? verify && isFunction t.verify; in @@ -14,7 +27,7 @@ lib.fix (self: { name = "string"; verify = isString; }; - str = self.string; # Type alias + str = self.string; # Type alias any = { name = "any"; @@ -46,31 +59,48 @@ lib.fix (self: { verify = isList; }; - attrsOf = t: assert isTypeDef t; let - inherit (t) verify; - in { - name = "attrsOf<${t.name}>"; - verify = - # attrsOf can be optimised to just isAttrs - if t == self.any then isAttrs - else attrs: isAttrs attrs && all verify (attrValues attrs); - }; + attrsOf = + t: + assert isTypeDef t; + let + inherit (t) verify; + in + { + name = "attrsOf<${t.name}>"; + verify = + # attrsOf can be optimised to just isAttrs + if t == self.any then isAttrs else attrs: isAttrs attrs && all verify (attrValues attrs); + }; - listOf = t: assert isTypeDef t; let - inherit (t) verify; - in { - name = "listOf<${t.name}>"; - verify = - # listOf can be optimised to just isList - if t == self.any then isList - else v: isList v && all verify v; - }; + listOf = + t: + assert isTypeDef t; + let + inherit (t) verify; + in + { + name = "listOf<${t.name}>"; + verify = + # listOf can be optimised to just isList + if t == self.any then isList else v: isList v && all verify v; + }; - union = types: assert all isTypeDef types; let - # Store a list of functions so we don't have to pay the cost of attrset lookups at runtime. - funcs = map (t: t.verify) types; - in { - name = "union<${concatStringsSep "," (map (t: t.name) types)}>"; - verify = v: any (func: func v) funcs; - }; + union = + types: + assert all isTypeDef types; + let + # Store a list of functions so we don't have to pay the cost of attrset lookups at runtime. + funcs = map (t: t.verify) types; + in + { + name = "union<${concatStringsSep "," (map (t: t.name) types)}>"; + verify = v: any (func: func v) funcs; + }; + enum = + values: + assert isList values && all isString values; + { + name = "enum<${concatStringsSep "," values}>"; + verify = v: isString v && elem v values; + }; }) diff --git a/pkgs/stdenv/generic/problems.nix b/pkgs/stdenv/generic/problems.nix index fd2e67e12047c..ff5f32d92a931 100644 --- a/pkgs/stdenv/generic/problems.nix +++ b/pkgs/stdenv/generic/problems.nix @@ -4,7 +4,11 @@ rec { # Problem handler levels - problemHandlers = [ "error" "warn" "ignore" ]; + problemHandlers = [ + "error" + "warn" + "ignore" + ]; # Take the maximum (highest severity) problem handler maxProblemHandler = @@ -14,8 +18,7 @@ rec { else if a == "warn" || b == "warn" then "warn" else - "ignore" - ; + "ignore"; # Currently known list of known problem kinds. Keep up to date with pkgs/top-level/config.nix problemKinds = [ @@ -40,7 +43,10 @@ rec { ]; # Same thing but a set with null values (comes in handy at times) problemKindsUnique' = lib.pipe problemKindsUnique [ - (map (name: { inherit name; value = null; })) + (map (name: { + inherit name; + value = null; + })) lib.listToAttrs ]; @@ -61,7 +67,7 @@ rec { # Take the problems plus add automatically generated ones problems = - (pkg.meta.problems or {}) + (pkg.meta.problems or { }) // lib.optionalAttrs (hasNoMaintainers pkg) { maintainerless = { message = "This package has no declared maintainer, i.e. an empty `meta.maintainers` attribute"; @@ -69,34 +75,37 @@ rec { }; # Inject default values, since metaTypes can't do it for us currently - addDefaults = name: problem: { inherit name; kind = name; } // problem; + addDefaults = + name: problem: + { + inherit name; + kind = name; + } + // problem; # Determine the handler level from config for this problem - addHandler = problem: + addHandler = + problem: let handler = # Try to find an explicit handler - (handlers.${pkgName} or {}).${problem.name} - # Fall back, iterating through the matchers - or ( - lib.pipe matchers [ + (handlers.${pkgName} or { }).${problem.name} + # Fall back, iterating through the matchers + or (lib.pipe matchers [ # Find matches - (lib.filter - (matcher: - (if matcher.name != null then problem.name == matcher.name else true) - && (if matcher.kind != null then problem.kind == matcher.kind else true) - && (if matcher.package != null then pkgName == matcher.package else true) - ) - ) + (lib.filter ( + matcher: + (if matcher.name != null then problem.name == matcher.name else true) + && (if matcher.kind != null then problem.kind == matcher.kind else true) + && (if matcher.package != null then pkgName == matcher.package else true) + )) # Extract handler level (builtins.map (lib.getAttr "handler")) # Take the strongest matched handler level (lib.foldl' maxProblemHandler "ignore") - ] - ); + ]); in problem // { inherit handler; }; in - builtins.map addHandler - (lib.mapAttrsToList addDefaults problems); + builtins.map addHandler (lib.mapAttrsToList addDefaults problems); } diff --git a/pkgs/test/problems/cases/deprecated-and-removal-and-maintainerless-error/default.nix b/pkgs/test/problems/cases/deprecated-and-removal-and-maintainerless-error/default.nix new file mode 100644 index 0000000000000..562c7594c5d17 --- /dev/null +++ b/pkgs/test/problems/cases/deprecated-and-removal-and-maintainerless-error/default.nix @@ -0,0 +1,23 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { + problems.handlers = { + "a"."deprecated" = "error"; + "a"."removal" = "error"; + "a"."maintainerless" = "error"; + }; + }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.problems = { + deprecated.message = "Package is deprecated and replaced by b"; + removal.message = "Package will be removed."; + }; + meta.maintainers = [ ]; +} diff --git a/pkgs/test/problems/cases/deprecated-and-removal-and-maintainerless-error/expected-stderr b/pkgs/test/problems/cases/deprecated-and-removal-and-maintainerless-error/expected-stderr new file mode 100644 index 0000000000000..7b72e3fc5052d --- /dev/null +++ b/pkgs/test/problems/cases/deprecated-and-removal-and-maintainerless-error/expected-stderr @@ -0,0 +1,38 @@ +error: Package ‘a-0’ in /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-default.nix:17 has some problem that must be acknowledged, refusing to evaluate. + + + +Package problems: + +- deprecated: Package is deprecated and replaced by b +- maintainerless: This package has no declared maintainer, i.e. an empty `meta.maintainers` attribute +- removal: Package will be removed. + +You can use it anyway by ignoring its problems, using one of the +following methods: + +a) For `nixos-rebuild` you can add "warn" or "ignore" entries to + `nixpkgs.config.problems.handlers` inside configuration.nix, + like this: + + { + nixpkgs.config.problems.handlers = { + "a"."deprecated" = "warn"; + "a"."maintainerless" = "warn"; + "a"."removal" = "warn"; + }; + } + +b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add + "warn" or "ignore" to `problems.handlers` in + ~/.config/nixpkgs/config.nix, like this: + + { + problems.handlers = { + "a"."deprecated" = "warn"; + "a"."maintainerless" = "warn"; + "a"."removal" = "warn"; + }; + } + +(use '--show-trace' to show detailed location information) diff --git a/pkgs/test/problems/cases/deprecated-and-removal-error/default.nix b/pkgs/test/problems/cases/deprecated-and-removal-error/default.nix new file mode 100644 index 0000000000000..20a18cc17c78e --- /dev/null +++ b/pkgs/test/problems/cases/deprecated-and-removal-error/default.nix @@ -0,0 +1,22 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { + problems.handlers = { + "a"."deprecated" = "error"; + "a"."removal" = "error"; + }; + }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.problems = { + deprecated.message = "Package is deprecated and replaced by b"; + removal.message = "Package will be removed"; + }; + meta.maintainers = [ "hello" ]; +} diff --git a/pkgs/test/problems/cases/deprecated-and-removal-error/expected-stderr b/pkgs/test/problems/cases/deprecated-and-removal-error/expected-stderr new file mode 100644 index 0000000000000..f5a0f1cce688d --- /dev/null +++ b/pkgs/test/problems/cases/deprecated-and-removal-error/expected-stderr @@ -0,0 +1,35 @@ +error: Package ‘a-0’ in /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-default.nix:16 has some problem that must be acknowledged, refusing to evaluate. + + + +Package problems: + +- deprecated: Package is deprecated and replaced by b +- removal: Package will be removed + +You can use it anyway by ignoring its problems, using one of the +following methods: + +a) For `nixos-rebuild` you can add "warn" or "ignore" entries to + `nixpkgs.config.problems.handlers` inside configuration.nix, + like this: + + { + nixpkgs.config.problems.handlers = { + "a"."deprecated" = "warn"; + "a"."removal" = "warn"; + }; + } + +b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add + "warn" or "ignore" to `problems.handlers` in + ~/.config/nixpkgs/config.nix, like this: + + { + problems.handlers = { + "a"."deprecated" = "warn"; + "a"."removal" = "warn"; + }; + } + +(use '--show-trace' to show detailed location information) diff --git a/pkgs/test/problems/cases/deprecated-error/default.nix b/pkgs/test/problems/cases/deprecated-error/default.nix new file mode 100644 index 0000000000000..405d394bd893f --- /dev/null +++ b/pkgs/test/problems/cases/deprecated-error/default.nix @@ -0,0 +1,20 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { + problems.handlers = { + "a"."deprecated" = "error"; + }; + }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.problems.deprecated = { + message = "Package is deprecated and replaced by b"; + }; + meta.maintainers = [ "hello" ]; +} diff --git a/pkgs/test/problems/cases/deprecated-error/expected-stderr b/pkgs/test/problems/cases/deprecated-error/expected-stderr new file mode 100644 index 0000000000000..13fdb8d1706ba --- /dev/null +++ b/pkgs/test/problems/cases/deprecated-error/expected-stderr @@ -0,0 +1,32 @@ +error: Package ‘a-0’ in /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-default.nix:15 has some problem that must be acknowledged, refusing to evaluate. + + + +Package problems: + +- deprecated: Package is deprecated and replaced by b + +You can use it anyway by ignoring its problems, using one of the +following methods: + +a) For `nixos-rebuild` you can add "warn" or "ignore" entries to + `nixpkgs.config.problems.handlers` inside configuration.nix, + like this: + + { + nixpkgs.config.problems.handlers = { + "a"."deprecated" = "warn"; + }; + } + +b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add + "warn" or "ignore" to `problems.handlers` in + ~/.config/nixpkgs/config.nix, like this: + + { + problems.handlers = { + "a"."deprecated" = "warn"; + }; + } + +(use '--show-trace' to show detailed location information) diff --git a/pkgs/test/problems/cases/deprecated-ignore/default.nix b/pkgs/test/problems/cases/deprecated-ignore/default.nix new file mode 100644 index 0000000000000..0ce36d2948423 --- /dev/null +++ b/pkgs/test/problems/cases/deprecated-ignore/default.nix @@ -0,0 +1,18 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { + problems.handlers = { + "a"."deprecated" = "ignore"; + }; + }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.problems.deprecated.message = "Package is deprecated and is replaced by b."; + meta.maintainers = [ "hello" ]; +} diff --git a/pkgs/test/problems/cases/deprecated-ignore/expected-stderr b/pkgs/test/problems/cases/deprecated-ignore/expected-stderr new file mode 100644 index 0000000000000..c255c1d5a32bd --- /dev/null +++ b/pkgs/test/problems/cases/deprecated-ignore/expected-stderr @@ -0,0 +1 @@ +warning: you did not specify '--add-root'; the result might be removed by the garbage collector diff --git a/pkgs/test/problems/cases/deprecated-warn/default.nix b/pkgs/test/problems/cases/deprecated-warn/default.nix new file mode 100644 index 0000000000000..bcafc3e96f6a7 --- /dev/null +++ b/pkgs/test/problems/cases/deprecated-warn/default.nix @@ -0,0 +1,18 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { + problems.handlers = { + "a"."deprecated" = "warn"; + }; + }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.problems.deprecated.message = "Package a is deprecated and superseeded by b."; + meta.maintainers = [ "hello" ]; +} diff --git a/pkgs/test/problems/cases/deprecated-warn/expected-stderr b/pkgs/test/problems/cases/deprecated-warn/expected-stderr new file mode 100644 index 0000000000000..a55882a849c09 --- /dev/null +++ b/pkgs/test/problems/cases/deprecated-warn/expected-stderr @@ -0,0 +1,2 @@ +trace: Package a-0 in /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-default.nix:15 has the following problems: [ "deprecated" ], continuing anyway. +warning: you did not specify '--add-root'; the result might be removed by the garbage collector diff --git a/pkgs/test/problems/cases/invalid-kind-error/default.nix b/pkgs/test/problems/cases/invalid-kind-error/default.nix new file mode 100644 index 0000000000000..a97437752acc1 --- /dev/null +++ b/pkgs/test/problems/cases/invalid-kind-error/default.nix @@ -0,0 +1,15 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.problems = { + invalid.message = "No maintainers"; + }; +} diff --git a/pkgs/test/problems/cases/invalid-kind-error/expected-stderr b/pkgs/test/problems/cases/invalid-kind-error/expected-stderr new file mode 100644 index 0000000000000..d27676672b6ac --- /dev/null +++ b/pkgs/test/problems/cases/invalid-kind-error/expected-stderr @@ -0,0 +1,7 @@ +error: Package ‘a-0’ in /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-default.nix:11 has an invalid meta attrset: + - key 'meta.problems.invalid.kind' has invalid value; expected one of "removal", "deprecated", got + "invalid" +, refusing to evaluate. + + +(use '--show-trace' to show detailed location information) diff --git a/pkgs/test/problems/cases/maintainerless-and-removal-and-deprecated-warn/default.nix b/pkgs/test/problems/cases/maintainerless-and-removal-and-deprecated-warn/default.nix new file mode 100644 index 0000000000000..9261c2e45fae9 --- /dev/null +++ b/pkgs/test/problems/cases/maintainerless-and-removal-and-deprecated-warn/default.nix @@ -0,0 +1,23 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { + problems.handlers = { + "a"."maintainerless" = "warn"; + "a"."deprecated" = "warn"; + "a"."removal" = "warn"; + }; + }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.maintainers = [ ]; + meta.problems = { + removal.message = "Package to be removed."; + deprecated.message = "Package will be deprecated"; + }; +} diff --git a/pkgs/test/problems/cases/maintainerless-and-removal-and-deprecated-warn/expected-stderr b/pkgs/test/problems/cases/maintainerless-and-removal-and-deprecated-warn/expected-stderr new file mode 100644 index 0000000000000..656f92bc94fca --- /dev/null +++ b/pkgs/test/problems/cases/maintainerless-and-removal-and-deprecated-warn/expected-stderr @@ -0,0 +1,2 @@ +trace: Package a-0 in /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-default.nix:17 has the following problems: [ "deprecated" "maintainerless" "removal" ], continuing anyway. +warning: you did not specify '--add-root'; the result might be removed by the garbage collector diff --git a/pkgs/test/problems/cases/maintainerless-and-removal-warn/default.nix b/pkgs/test/problems/cases/maintainerless-and-removal-warn/default.nix new file mode 100644 index 0000000000000..82266eafa95c6 --- /dev/null +++ b/pkgs/test/problems/cases/maintainerless-and-removal-warn/default.nix @@ -0,0 +1,19 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { + problems.handlers = { + "a"."maintainerless" = "warn"; + "a"."removal" = "warn"; + }; + }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.maintainers = [ ]; + meta.problems.removal.message = "Package will be removed."; +} diff --git a/pkgs/test/problems/cases/maintainerless-and-removal-warn/expected-stderr b/pkgs/test/problems/cases/maintainerless-and-removal-warn/expected-stderr new file mode 100644 index 0000000000000..1f8e51654aff6 --- /dev/null +++ b/pkgs/test/problems/cases/maintainerless-and-removal-warn/expected-stderr @@ -0,0 +1,2 @@ +trace: Package a-0 in /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-default.nix:16 has the following problems: [ "maintainerless" "removal" ], continuing anyway. +warning: you did not specify '--add-root'; the result might be removed by the garbage collector diff --git a/pkgs/test/problems/cases/maintainerless-error/default.nix b/pkgs/test/problems/cases/maintainerless-error/default.nix new file mode 100644 index 0000000000000..150e623a4bdff --- /dev/null +++ b/pkgs/test/problems/cases/maintainerless-error/default.nix @@ -0,0 +1,17 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { + problems.handlers = { + "a"."maintainerless" = "error"; + }; + }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.maintainers = [ ]; +} diff --git a/pkgs/test/problems/cases/maintainerless-error/expected-stderr b/pkgs/test/problems/cases/maintainerless-error/expected-stderr new file mode 100644 index 0000000000000..176fd604057ba --- /dev/null +++ b/pkgs/test/problems/cases/maintainerless-error/expected-stderr @@ -0,0 +1,32 @@ +error: Package ‘a-0’ in /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-default.nix:15 has some problem that must be acknowledged, refusing to evaluate. + + + +Package problems: + +- maintainerless: This package has no declared maintainer, i.e. an empty `meta.maintainers` attribute + +You can use it anyway by ignoring its problems, using one of the +following methods: + +a) For `nixos-rebuild` you can add "warn" or "ignore" entries to + `nixpkgs.config.problems.handlers` inside configuration.nix, + like this: + + { + nixpkgs.config.problems.handlers = { + "a"."maintainerless" = "warn"; + }; + } + +b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add + "warn" or "ignore" to `problems.handlers` in + ~/.config/nixpkgs/config.nix, like this: + + { + problems.handlers = { + "a"."maintainerless" = "warn"; + }; + } + +(use '--show-trace' to show detailed location information) diff --git a/pkgs/test/problems/cases/maintainerless-ignore/default.nix b/pkgs/test/problems/cases/maintainerless-ignore/default.nix new file mode 100644 index 0000000000000..8531510073d40 --- /dev/null +++ b/pkgs/test/problems/cases/maintainerless-ignore/default.nix @@ -0,0 +1,17 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { + problems.handlers = { + "a"."maintainerless" = "ignore"; + }; + }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.maintainers = [ ]; +} diff --git a/pkgs/test/problems/cases/maintainerless-ignore/expected-stderr b/pkgs/test/problems/cases/maintainerless-ignore/expected-stderr new file mode 100644 index 0000000000000..c255c1d5a32bd --- /dev/null +++ b/pkgs/test/problems/cases/maintainerless-ignore/expected-stderr @@ -0,0 +1 @@ +warning: you did not specify '--add-root'; the result might be removed by the garbage collector diff --git a/pkgs/test/problems/cases/maintainerless-warn/default.nix b/pkgs/test/problems/cases/maintainerless-warn/default.nix new file mode 100644 index 0000000000000..75708dcd42ad5 --- /dev/null +++ b/pkgs/test/problems/cases/maintainerless-warn/default.nix @@ -0,0 +1,17 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { + problems.handlers = { + "a"."maintainerless" = "warn"; + }; + }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.maintainers = [ ]; +} diff --git a/pkgs/test/problems/cases/maintainerless-warn/expected-stderr b/pkgs/test/problems/cases/maintainerless-warn/expected-stderr new file mode 100644 index 0000000000000..45fd822f0feb5 --- /dev/null +++ b/pkgs/test/problems/cases/maintainerless-warn/expected-stderr @@ -0,0 +1,2 @@ +trace: Package a-0 in /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-default.nix:15 has the following problems: [ "maintainerless" ], continuing anyway. +warning: you did not specify '--add-root'; the result might be removed by the garbage collector diff --git a/pkgs/test/problems/cases/no-problems/default.nix b/pkgs/test/problems/cases/no-problems/default.nix new file mode 100644 index 0000000000000..f7b14483233d9 --- /dev/null +++ b/pkgs/test/problems/cases/no-problems/default.nix @@ -0,0 +1,15 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { + problems.handlers = { }; + }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.maintainers = [ "hello" ]; +} diff --git a/pkgs/test/problems/cases/no-problems/expected-stderr b/pkgs/test/problems/cases/no-problems/expected-stderr new file mode 100644 index 0000000000000..c255c1d5a32bd --- /dev/null +++ b/pkgs/test/problems/cases/no-problems/expected-stderr @@ -0,0 +1 @@ +warning: you did not specify '--add-root'; the result might be removed by the garbage collector diff --git a/pkgs/test/problems/cases/removal-error/default.nix b/pkgs/test/problems/cases/removal-error/default.nix new file mode 100644 index 0000000000000..43b62a3fcf51b --- /dev/null +++ b/pkgs/test/problems/cases/removal-error/default.nix @@ -0,0 +1,15 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.problems = { + removal.message = "This package has been abandoned upstream and will be removed"; + }; +} diff --git a/pkgs/test/problems/cases/removal-error/expected-stderr b/pkgs/test/problems/cases/removal-error/expected-stderr new file mode 100644 index 0000000000000..915218a9ad024 --- /dev/null +++ b/pkgs/test/problems/cases/removal-error/expected-stderr @@ -0,0 +1,32 @@ +error: Package ‘a-0’ in /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-default.nix:11 has some problem that must be acknowledged, refusing to evaluate. + + + +Package problems: + +- removal: This package has been abandoned upstream and will be removed + +You can use it anyway by ignoring its problems, using one of the +following methods: + +a) For `nixos-rebuild` you can add "warn" or "ignore" entries to + `nixpkgs.config.problems.handlers` inside configuration.nix, + like this: + + { + nixpkgs.config.problems.handlers = { + "a"."removal" = "warn"; + }; + } + +b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add + "warn" or "ignore" to `problems.handlers` in + ~/.config/nixpkgs/config.nix, like this: + + { + problems.handlers = { + "a"."removal" = "warn"; + }; + } + +(use '--show-trace' to show detailed location information) diff --git a/pkgs/test/problems/cases/removal-ignore/default.nix b/pkgs/test/problems/cases/removal-ignore/default.nix new file mode 100644 index 0000000000000..0cccb8873b276 --- /dev/null +++ b/pkgs/test/problems/cases/removal-ignore/default.nix @@ -0,0 +1,17 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { + problems.handlers = { + "a"."removal" = "ignore"; + }; + }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.problems.removal.message = "To be removed"; +} diff --git a/pkgs/test/problems/cases/removal-ignore/expected-stderr b/pkgs/test/problems/cases/removal-ignore/expected-stderr new file mode 100644 index 0000000000000..c255c1d5a32bd --- /dev/null +++ b/pkgs/test/problems/cases/removal-ignore/expected-stderr @@ -0,0 +1 @@ +warning: you did not specify '--add-root'; the result might be removed by the garbage collector diff --git a/pkgs/test/problems/cases/removal-twice-error/default.nix b/pkgs/test/problems/cases/removal-twice-error/default.nix new file mode 100644 index 0000000000000..c2dec5f6d7cf7 --- /dev/null +++ b/pkgs/test/problems/cases/removal-twice-error/default.nix @@ -0,0 +1,21 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.problems = { + removal = { + message = "This package has been abandoned upstream and will be removed"; + }; + removal2 = { + kind = "removal"; + message = "This package has been abandoned upstream and will be removed2"; + }; + }; +} diff --git a/pkgs/test/problems/cases/removal-twice-error/expected-stderr b/pkgs/test/problems/cases/removal-twice-error/expected-stderr new file mode 100644 index 0000000000000..63b7c9eecfad1 --- /dev/null +++ b/pkgs/test/problems/cases/removal-twice-error/expected-stderr @@ -0,0 +1,6 @@ +error: Package ‘a-0’ in /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-default.nix:11 has an invalid meta attrset: + - keys [ 'meta.problems.removal' 'meta.problems.removal2' ] all have the same problem kind, which is not allowed for kind 'removal' +, refusing to evaluate. + + +(use '--show-trace' to show detailed location information) diff --git a/pkgs/test/problems/cases/removal-warn/default.nix b/pkgs/test/problems/cases/removal-warn/default.nix new file mode 100644 index 0000000000000..0044c2fc39e09 --- /dev/null +++ b/pkgs/test/problems/cases/removal-warn/default.nix @@ -0,0 +1,18 @@ +{ nixpkgs }: +let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + config = { + problems.handlers = { + "a"."removal" = "warn"; + }; + }; + }; +in +pkgs.stdenvNoCC.mkDerivation { + pname = "a"; + version = "0"; + meta.maintainers = [ "hello" ]; + meta.problems.removal.message = "Package to be removed."; +} diff --git a/pkgs/test/problems/cases/removal-warn/expected-stderr b/pkgs/test/problems/cases/removal-warn/expected-stderr new file mode 100644 index 0000000000000..93f814163896c --- /dev/null +++ b/pkgs/test/problems/cases/removal-warn/expected-stderr @@ -0,0 +1,2 @@ +trace: Package a-0 in /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-default.nix:15 has the following problems: [ "removal" ], continuing anyway. +warning: you did not specify '--add-root'; the result might be removed by the garbage collector diff --git a/pkgs/test/problems/default.nix b/pkgs/test/problems/default.nix index 26fe640673d56..3366c3688eda8 100644 --- a/pkgs/test/problems/default.nix +++ b/pkgs/test/problems/default.nix @@ -1,7 +1,7 @@ { lib, nixVersions, - runCommandNoCC, + runCommand, removeReferencesTo, path, }: @@ -12,11 +12,7 @@ lib.mapAttrs ( name: _: let nixFile = "${./cases + "/${name}/default.nix"}"; - result = runCommandNoCC "test-problems-${name}" { - nativeBuildInputs = [ - removeReferencesTo - ]; - } '' + result = runCommand "test-problems-${name}" { nativeBuildInputs = [ removeReferencesTo ]; } '' export NIX_STATE_DIR=$(mktemp -d) mkdir $out @@ -41,7 +37,7 @@ lib.mapAttrs ( echo "Command exited with code $(<$out/code)" remove-references-to -t ${nixFile} $out/* ''; - checker = runCommandNoCC "test-problems-check-${name}" { } '' + checker = runCommand "test-problems-check-${name}" { } '' if ! diff ${result}/stderr ${./cases + "/${name}/expected-stderr"}; then echo "Output of $(< ${result}/command) does not match what was expected (${result}/stderr)" exit 1