Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pkgs/stdenv/generic/check-meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ let

isMarkedInsecure = attrs: (attrs.meta.knownVulnerabilities or []) != [];

unstructuredArrays = attrs:
let
arrayVariables =
builtins.filter
(name: builtins.match "^.*Array$" name != null)
(builtins.attrNames attrs);
__structuredAttrs = attrs.__structuredAttrs or config.structuredAttrsByDefault;
in
if __structuredAttrs then [] else arrayVariables;

# Alow granular checks to allow only some unfree packages
# Example:
# {pkgs, ...}:
Expand Down Expand Up @@ -171,6 +181,7 @@ let
broken-outputs = remediateOutputsToInstall;
unknown-meta = x: "";
maintainerless = x: "";
unstructured-arrays = x: "";
};
remediation_env_var = allow_attr: {
Unfree = "NIXPKGS_ALLOW_UNFREE";
Expand Down Expand Up @@ -439,6 +450,18 @@ let
# Please also update the type in /pkgs/top-level/config.nix alongside this.
else if hasNoMaintainers attrs then
{ valid = "warn"; reason = "maintainerless"; errormsg = "has no maintainers"; }
else if unstructuredArrays attrs != [] then
let
quote = s: ''"${s}"'';
variables = unstructuredArrays attrs;
variablesStr = builtins.concatStringsSep ", " (map quote variables);
usePlural = variables != [(builtins.head variables)];
plural = optionalString usePlural "s";
Comment on lines +455 to +459

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty cute.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we’re spelling lib.length variables != 1 like that…?

in
{ valid = "warn";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @wolfgangwalther that this ought to be an error, but the set of packages it touches is pretty high. We'll patch it all up in the next staging-next.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to consider out‐of‐tree users too. I agree with the suggestion to add the “this will break” warning and then make it a hard error on the next release.

reason = "unstructured-arrays";
errormsg = "The variable${plural} ${variablesStr} will be misinterpreted as single element bash array${plural} because __structuredAttrs is not set";
}
# -----
else validYes;

Expand Down
4 changes: 2 additions & 2 deletions pkgs/top-level/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ let
};

showDerivationWarnings = mkOption {
type = types.listOf (types.enum [ "maintainerless" ]);
default = [];
type = types.listOf (types.enum [ "maintainerless" "unstructured-arrays" ]);
default = [ "unstructured-arrays" ];
description = ''
Which warnings to display for potentially dangerous
or deprecated values passed into `stdenv.mkDerivation`.
Expand Down