From f886d6e9e8cd1e7ad07089a8a80f1fe027c5392d Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 18 May 2022 20:21:01 -0700 Subject: [PATCH 1/5] lib/types.nix: listOf.check needs to check the elements Prior to this commit, the `check` method in the `listOf` type in `lib/types.nix` would accept *any* list, even if the list was not in fact a "list of" the specified type. This meant that for checking purposes, `listOf bool` and `listOf int` were the same thing. This commit fixes that problem. --- lib/types.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/types.nix b/lib/types.nix index 2590d3e8710b3..7cce5178b451a 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -397,8 +397,8 @@ rec { listOf = elemType: mkOptionType rec { name = "listOf"; - description = "list of ${elemType.description}"; - check = isList; + description = "list of ${elemType.description}s"; + check = v: isList v && all (elemType.check) v; merge = loc: defs: map (x: x.value) (filter (x: x ? value) (concatLists (imap1 (n: def: imap1 (m: def': From ebab13db9add61aa659988b051f2adab3370c1c8 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 18 May 2022 22:12:36 -0700 Subject: [PATCH 2/5] fix meta.* type errors for PR #173568 --- pkgs/applications/misc/keepass-plugins/otpkeyprov/default.nix | 2 +- pkgs/applications/window-managers/sway/contrib.nix | 4 ++-- pkgs/development/tools/parsing/javacc/default.nix | 2 +- pkgs/games/quake3/quake3e/default.nix | 2 +- pkgs/stdenv/generic/check-meta.nix | 2 +- pkgs/tools/security/ghidra/build.nix | 2 +- pkgs/tools/security/onlykey-agent/default.nix | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkgs/applications/misc/keepass-plugins/otpkeyprov/default.nix b/pkgs/applications/misc/keepass-plugins/otpkeyprov/default.nix index 780de142c5fd7..d7a80a595495e 100644 --- a/pkgs/applications/misc/keepass-plugins/otpkeyprov/default.nix +++ b/pkgs/applications/misc/keepass-plugins/otpkeyprov/default.nix @@ -17,7 +17,7 @@ let homepage = "https://keepass.info/plugins.html#otpkeyprov"; platforms = with lib.platforms; linux; license = lib.licenses.gpl2; - maintainers = [ lib.maintainers.ente ]; + maintainers = [ /*lib.maintainers.ente*/ ]; }; pluginFilename = "OtpKeyProv.plgx"; diff --git a/pkgs/applications/window-managers/sway/contrib.nix b/pkgs/applications/window-managers/sway/contrib.nix index a221eb7a8e65b..5c0c4ade0c377 100644 --- a/pkgs/applications/window-managers/sway/contrib.nix +++ b/pkgs/applications/window-managers/sway/contrib.nix @@ -62,8 +62,8 @@ grimshot = stdenv.mkDerivation rec { homepage = "https://github.com/swaywm/sway/tree/master/contrib"; license = licenses.mit; platforms = platforms.all; - maintainers = with maintainers; [ - sway-unwrapped.meta.maintainers + maintainers = with maintainers; + sway-unwrapped.meta.maintainers ++ [ evils ]; }; diff --git a/pkgs/development/tools/parsing/javacc/default.nix b/pkgs/development/tools/parsing/javacc/default.nix index d074e3dda93e6..a3adad076cf06 100644 --- a/pkgs/development/tools/parsing/javacc/default.nix +++ b/pkgs/development/tools/parsing/javacc/default.nix @@ -27,6 +27,6 @@ stdenv.mkDerivation rec { homepage = "https://javacc.github.io/javacc"; description = "A parser generator for building parsers from grammars"; license = licenses.bsd2; - maintainers = [ teams.deshaw.members ]; + maintainers = teams.deshaw.members; }; } diff --git a/pkgs/games/quake3/quake3e/default.nix b/pkgs/games/quake3/quake3e/default.nix index 2346e6022d94f..c32cf153c4f6a 100644 --- a/pkgs/games/quake3/quake3e/default.nix +++ b/pkgs/games/quake3/quake3e/default.nix @@ -47,6 +47,6 @@ stdenv.mkDerivation rec { license = licenses.gpl2; platforms = platforms.linux; maintainers = with maintainers; [ pmiddend ]; - badPlatforms = [ platforms.aarch64 ]; + badPlatforms = platforms.aarch64; }; } diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix index 1da098dabbee1..47ff6df935b01 100644 --- a/pkgs/stdenv/generic/check-meta.nix +++ b/pkgs/stdenv/generic/check-meta.nix @@ -225,7 +225,7 @@ let homepage = either (listOf str) str; downloadPage = str; changelog = either (listOf str) str; - license = either (listOf lib.types.attrs) (either lib.types.attrs str); + license = let license = either lib.types.attrs str; in either license (listOf license); maintainers = listOf (attrsOf str); priority = int; platforms = listOf str; diff --git a/pkgs/tools/security/ghidra/build.nix b/pkgs/tools/security/ghidra/build.nix index bb53a1958e000..e4f87d06e5308 100644 --- a/pkgs/tools/security/ghidra/build.nix +++ b/pkgs/tools/security/ghidra/build.nix @@ -172,7 +172,7 @@ in stdenv.mkDerivation rec { homepage = "https://ghidra-sre.org/"; platforms = [ "x86_64-linux" "x86_64-darwin" ]; license = licenses.asl20; - maintainers = [ "roblabla" ]; + maintainers = with maintainers; [ roblabla ]; }; } diff --git a/pkgs/tools/security/onlykey-agent/default.nix b/pkgs/tools/security/onlykey-agent/default.nix index 84c65b913458a..05d1e7ca37e8e 100644 --- a/pkgs/tools/security/onlykey-agent/default.nix +++ b/pkgs/tools/security/onlykey-agent/default.nix @@ -26,7 +26,7 @@ let meta = oa.meta // { description = "Using OnlyKey as hardware SSH and GPG agent"; homepage = "https://github.com/trustcrypto/onlykey-agent/tree/ledger"; - maintainers = with maintainers; [ kalbasit ]; + maintainers = with lib.maintainers; [ kalbasit ]; }; }); in From 61d0c9f52f9f026d7919761c2d96e415efcf2792 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Thu, 19 May 2022 15:37:01 -0700 Subject: [PATCH 3/5] Implement @ckiee's recommendation https://github.com/NixOS/nixpkgs/pull/173568#issuecomment-1131500670 --- lib/types.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/types.nix b/lib/types.nix index 7cce5178b451a..6be39ef196e30 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -398,7 +398,7 @@ rec { listOf = elemType: mkOptionType rec { name = "listOf"; description = "list of ${elemType.description}s"; - check = v: isList v && all (elemType.check) v; + check = v: isList v && all (e: elemType.check e || e ? _type ) v; merge = loc: defs: map (x: x.value) (filter (x: x ? value) (concatLists (imap1 (n: def: imap1 (m: def': From f979d746ad320461e20558faccbdf621c9cd1051 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Thu, 19 May 2022 17:54:40 -0700 Subject: [PATCH 4/5] split types.listOf into the "nixos version" and the "nix version" --- lib/types.nix | 11 ++++++++--- .../manual/development/option-types.section.md | 10 ++++++++-- pkgs/pkgs-lib/formats.nix | 10 +++++----- pkgs/stdenv/generic/check-meta.nix | 18 +++++++++--------- pkgs/top-level/config.nix | 4 ++-- 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/lib/types.nix b/lib/types.nix index 6be39ef196e30..9e6cc1768adc3 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -163,7 +163,7 @@ rec { # When adding new types don't forget to document them in - # nixos/doc/manual/development/option-types.xml! + # nixos/doc/manual/development/option-types.section.md! types = rec { raw = mkOptionType rec { @@ -395,10 +395,12 @@ rec { merge = mergeEqualOption; }; - listOf = elemType: mkOptionType rec { + # NixOS apparently has a different notion of "type" than nix(lang) + # does; see discussion in GH #173568 + listOfGeneralized = isNixOS: elemType: mkOptionType rec { name = "listOf"; description = "list of ${elemType.description}s"; - check = v: isList v && all (e: elemType.check e || e ? _type ) v; + check = v: isList v && (isNixOS || all elemType.check v); merge = loc: defs: map (x: x.value) (filter (x: x ? value) (concatLists (imap1 (n: def: imap1 (m: def': @@ -417,6 +419,9 @@ rec { nestedTypes.elemType = elemType; }; + listOf = listOfGeneralized true; + listOf' = listOfGeneralized false; + nonEmptyListOf = elemType: let list = addCheck (types.listOf elemType) (l: l != []); in list // { diff --git a/nixos/doc/manual/development/option-types.section.md b/nixos/doc/manual/development/option-types.section.md index 00f1d85bdb615..fc8f05b48e9ca 100644 --- a/nixos/doc/manual/development/option-types.section.md +++ b/nixos/doc/manual/development/option-types.section.md @@ -227,8 +227,14 @@ Composed types are types that take a type as parameter. `listOf `types.listOf` *`t`* -: A list of *`t`* type, e.g. `types.listOf - int`. Multiple definitions are merged with list concatenation. +: A list, probably but not certainly of *`t`* type, e.g. `types.listOf + int`. Multiple definitions are merged with list concatenation. The + `check` method will not examine the types of the list elements. + +`types.listOf'` *`t`* + +: A list of *`t`* type, e.g. `types.listOf' int`. Multiple definitions + are merged with list concatenation. `types.attrsOf` *`t`* diff --git a/pkgs/pkgs-lib/formats.nix b/pkgs/pkgs-lib/formats.nix index cb46b63dd0c49..13bd31d6f9748 100644 --- a/pkgs/pkgs-lib/formats.nix +++ b/pkgs/pkgs-lib/formats.nix @@ -44,7 +44,7 @@ rec { str path (attrsOf valueType) - (listOf valueType) + (listOf' valueType) ]) // { description = "JSON value"; }; @@ -78,7 +78,7 @@ rec { str path (attrsOf valueType) - (listOf valueType) + (listOf' valueType) ]) // { description = "YAML value"; }; @@ -110,7 +110,7 @@ rec { iniAtom = if listsAsDuplicateKeys then - coercedTo singleIniAtom lib.singleton (listOf singleIniAtom) // { + coercedTo singleIniAtom lib.singleton (listOf' singleIniAtom) // { description = singleIniAtom.description + " or a list of them for duplicate keys"; } else if listToValue != null then @@ -155,7 +155,7 @@ rec { str path (attrsOf valueType) - (listOf valueType) + (listOf' valueType) ] // { description = "TOML value"; }; @@ -269,7 +269,7 @@ rec { float str (attrsOf valueType) - (listOf valueType) + (listOf' valueType) ]) // { description = "Elixir value"; }; diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix index 47ff6df935b01..217de4b858249 100644 --- a/pkgs/stdenv/generic/check-meta.nix +++ b/pkgs/stdenv/generic/check-meta.nix @@ -222,14 +222,14 @@ let mainProgram = str; longDescription = str; branch = str; - homepage = either (listOf str) str; + homepage = either (listOf' str) str; downloadPage = str; - changelog = either (listOf str) str; - license = let license = either lib.types.attrs str; in either license (listOf license); - maintainers = listOf (attrsOf str); + changelog = either (listOf' str) str; + license = let license = either lib.types.attrs str; in either license (listOf' license); + maintainers = listOf' (attrsOf str); priority = int; - platforms = listOf str; - hydraPlatforms = listOf str; + platforms = listOf' str; + hydraPlatforms = listOf' str; broken = bool; unfree = bool; unsupported = bool; @@ -248,12 +248,12 @@ let # Weirder stuff that doesn't appear in the documentation? maxSilent = int; - knownVulnerabilities = listOf str; + knownVulnerabilities = listOf' str; name = str; version = str; tag = str; - executables = listOf str; - outputsToInstall = listOf str; + executables = listOf' str; + outputsToInstall = listOf' str; position = str; available = bool; isBuildPythonPackage = platforms; diff --git a/pkgs/top-level/config.nix b/pkgs/top-level/config.nix index 8c15e63e5fb1d..4a06dedb9ca4a 100644 --- a/pkgs/top-level/config.nix +++ b/pkgs/top-level/config.nix @@ -21,7 +21,7 @@ let /* Internal stuff */ warnings = mkOption { - type = types.listOf types.str; + type = types.listOf' types.str; default = []; internal = true; }; @@ -99,7 +99,7 @@ let }; showDerivationWarnings = mkOption { - type = types.listOf (types.enum [ "maintainerless" ]); + type = types.listOf' (types.enum [ "maintainerless" ]); default = []; description = '' Which warnings to display for potentially dangerous From 0c47b6d96b75fe2266ad99753458fd997b5799cb Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Thu, 19 May 2022 18:00:43 -0700 Subject: [PATCH 5/5] regenerate manual docbook --- .../development/option-types.section.xml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/nixos/doc/manual/from_md/development/option-types.section.xml b/nixos/doc/manual/from_md/development/option-types.section.xml index 4447292927021..5243759eb4ff0 100644 --- a/nixos/doc/manual/from_md/development/option-types.section.xml +++ b/nixos/doc/manual/from_md/development/option-types.section.xml @@ -442,10 +442,26 @@ types.listOf t + + + A list, probably but not certainly of + t type, e.g. + types.listOf int. Multiple definitions + are merged with list concatenation. The + check method will not examine the types + of the list elements. + + + + + + types.listOf' + t + A list of t type, - e.g. types.listOf int. Multiple + e.g. types.listOf' int. Multiple definitions are merged with list concatenation.