From f13654fe8a4cb1dccf47064cf0742dd277d3892e Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Tue, 10 Jun 2025 16:28:50 -0700 Subject: [PATCH 1/3] formats: extract things needed from lib in the let binding It's more vertical space but it ought to be more performant. --- pkgs/pkgs-lib/formats.nix | 103 +++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 36 deletions(-) diff --git a/pkgs/pkgs-lib/formats.nix b/pkgs/pkgs-lib/formats.nix index dc5118c537a1..096000cba925 100644 --- a/pkgs/pkgs-lib/formats.nix +++ b/pkgs/pkgs-lib/formats.nix @@ -1,7 +1,39 @@ { lib, pkgs }: let + inherit (lib) + concatStringsSep + escape + flatten + id + isAttrs + isFloat + isInt + isList + isString + mapAttrs + mapAttrsToList + mkOption + optionalAttrs + optionalString + pipe + types + singleton + warn + ; + + inherit (lib.generators) + mkValueStringDefault + toGitINI + toINI + toINIWithGlobalSection + toKeyValue + toLua + mkLuaInline + ; + inherit (lib.types) attrsOf + atom bool coercedTo either @@ -15,6 +47,7 @@ let oneOf path str + submodule ; # Attributes added accidentally in https://github.com/NixOS/nixpkgs/pull/335232 (2024-08-18) @@ -40,7 +73,7 @@ let ; }; in -lib.optionalAttrs pkgs.config.allowAliases aliases +optionalAttrs allowAliases aliases // rec { /* @@ -188,7 +221,7 @@ lib.optionalAttrs pkgs.config.allowAliases aliases }: let singleIniAtomOr = - if atomsCoercedToLists then coercedTo singleIniAtom lib.singleton else either singleIniAtom; + if atomsCoercedToLists then coercedTo singleIniAtom singleton else either singleIniAtom; in if listsAsDuplicateKeys then singleIniAtomOr (listOf singleIniAtom) @@ -212,9 +245,9 @@ lib.optionalAttrs pkgs.config.allowAliases aliases maybeToList = listToValue: if listToValue != null then - lib.mapAttrs (key: val: if lib.isList val then listToValue val else val) + mapAttrs (key: val: if isList val then listToValue val else val) else - lib.id; + id; in { ini = @@ -239,14 +272,14 @@ lib.optionalAttrs pkgs.config.allowAliases aliases in { - type = lib.types.attrsOf (iniSection atom); + type = attrsOf (iniSection atom); lib.types.atom = atom; generate = name: value: - lib.pipe value [ - (lib.mapAttrs (_: maybeToList listToValue)) - (lib.generators.toINI ( + pipe value [ + (mapAttrs (_: maybeToList listToValue)) + (toINI ( removeAttrs args [ "listToValue" "atomsCoercedToLists" @@ -277,14 +310,14 @@ lib.optionalAttrs pkgs.config.allowAliases aliases }; in { - type = lib.types.submodule { + type = submodule { options = { - sections = lib.mkOption rec { - type = lib.types.attrsOf (iniSection atom); + sections = mkOption rec { + type = attrsOf (iniSection atom); default = { }; description = type.description; }; - globalSection = lib.mkOption rec { + globalSection = mkOption rec { type = iniSection atom; default = { }; description = "global " + type.description; @@ -300,14 +333,14 @@ lib.optionalAttrs pkgs.config.allowAliases aliases ... }: pkgs.writeText name ( - lib.generators.toINIWithGlobalSection + toINIWithGlobalSection (removeAttrs args [ "listToValue" "atomsCoercedToLists" ]) { globalSection = maybeToList listToValue globalSection; - sections = lib.mapAttrs (_: maybeToList listToValue) sections; + sections = mapAttrs (_: maybeToList listToValue) sections; } ); }; @@ -327,7 +360,7 @@ lib.optionalAttrs pkgs.config.allowAliases aliases { type = attrsOf (attrsOf (either atom (attrsOf atom))); lib.types.atom = atom; - generate = name: value: pkgs.writeText name (lib.generators.toGitINI value); + generate = name: value: pkgs.writeText name (toGitINI value); }; } @@ -343,7 +376,7 @@ lib.optionalAttrs pkgs.config.allowAliases aliases # optional config options. systemd = let - mkValueString = lib.generators.mkValueStringDefault { }; + mkValueString = mkValueStringDefault { }; mkKeyValue = k: v: if v == null then "# ${k} is unset" else "${k} = ${mkValueString v}"; in ini { @@ -379,12 +412,12 @@ lib.optionalAttrs pkgs.config.allowAliases aliases atom = if listsAsDuplicateKeys then - coercedTo singleAtom lib.singleton (listOf singleAtom) + coercedTo singleAtom singleton (listOf singleAtom) // { description = singleAtom.description + " or a list of them for duplicate keys"; } else if listToValue != null then - coercedTo singleAtom lib.singleton (nonEmptyListOf singleAtom) + coercedTo singleAtom singleton (nonEmptyListOf singleAtom) // { description = singleAtom.description + " or a non-empty list of them"; } @@ -399,13 +432,11 @@ lib.optionalAttrs pkgs.config.allowAliases aliases let transformedValue = if listToValue != null then - lib.mapAttrs (key: val: if lib.isList val then listToValue val else val) value + mapAttrs (key: val: if isList val then listToValue val else val) value else value; in - pkgs.writeText name ( - lib.generators.toKeyValue (removeAttrs args [ "listToValue" ]) transformedValue - ); + pkgs.writeText name (toKeyValue (removeAttrs args [ "listToValue" ]) transformedValue); }; @@ -543,18 +574,18 @@ lib.optionalAttrs pkgs.config.allowAliases aliases "true" else if value == false then "false" - else if lib.isInt value || lib.isFloat value then + else if isInt value || isFloat value then toString value - else if lib.isString value then + else if isString value then string value - else if lib.isAttrs value then + else if isAttrs value then attrs value - else if lib.isList value then + else if isList value then list value else abort "formats.elixirConf: should never happen (value = ${value})"; - escapeElixir = lib.escape [ + escapeElixir = escape [ "\\" "#" "\"" @@ -568,11 +599,11 @@ lib.optionalAttrs pkgs.config.allowAliases aliases else let toKeyword = name: value: "${name}: ${toElixir value}"; - keywordList = lib.concatStringsSep ", " (lib.mapAttrsToList toKeyword set); + keywordList = concatStringsSep ", " (mapAttrsToList toKeyword set); in "[" + keywordList + "]"; - listContent = values: lib.concatStringsSep ", " (map toElixir values); + listContent = values: concatStringsSep ", " (map toElixir values); list = values: "[" + (listContent values) + "]"; @@ -593,7 +624,7 @@ lib.optionalAttrs pkgs.config.allowAliases aliases set: let toEntry = name: value: "${toElixir name} => ${toElixir value}"; - entries = lib.concatStringsSep ", " (lib.mapAttrsToList toEntry set); + entries = concatStringsSep ", " (mapAttrsToList toEntry set); in "%{${entries}}"; @@ -605,13 +636,13 @@ lib.optionalAttrs pkgs.config.allowAliases aliases keyConfig = rootKey: key: value: "config ${rootKey}, ${key}, ${toElixir value}"; - keyConfigs = rootKey: values: lib.mapAttrsToList (keyConfig rootKey) values; - rootConfigs = lib.flatten (lib.mapAttrsToList keyConfigs values); + keyConfigs = rootKey: values: mapAttrsToList (keyConfig rootKey) values; + rootConfigs = flatten (mapAttrsToList keyConfigs values); in '' import Config - ${lib.concatStringsSep "\n" rootConfigs} + ${concatStringsSep "\n" rootConfigs} ''; in { @@ -715,7 +746,7 @@ lib.optionalAttrs pkgs.config.allowAliases aliases # Wrap standard types, since anything in the Elixir configuration # can be raw Elixir } - // lib.mapAttrs (_name: type: elixirOr type) lib.types; + // mapAttrs (_name: type: elixirOr type) types; }; generate = @@ -771,12 +802,12 @@ lib.optionalAttrs pkgs.config.allowAliases aliases inherit columnWidth; inherit indentWidth; indentType = if indentUsingTabs then "Tabs" else "Spaces"; - value = lib.generators.toLua { inherit asBindings multiline; } value; + value = toLua { inherit asBindings multiline; } value; passAsFile = [ "value" ]; preferLocalBuild = true; } '' - ${lib.optionalString (!asBindings) '' + ${optionalString (!asBindings) '' echo -n 'return ' >> $out ''} cat $valuePath >> $out From a822df313f4d687d897767f5612f860398dfd41e Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Tue, 10 Jun 2025 16:29:36 -0700 Subject: [PATCH 2/3] formats: extract things needed from pkgs in the let binding This is an attempt to solve the NixOS manual failures seen in https://github.com/NixOS/nixpkgs/pull/415662 --- pkgs/pkgs-lib/formats.nix | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/pkgs/pkgs-lib/formats.nix b/pkgs/pkgs-lib/formats.nix index 096000cba925..9113d8ec3307 100644 --- a/pkgs/pkgs-lib/formats.nix +++ b/pkgs/pkgs-lib/formats.nix @@ -52,26 +52,26 @@ let # Attributes added accidentally in https://github.com/NixOS/nixpkgs/pull/335232 (2024-08-18) # Deprecated in https://github.com/NixOS/nixpkgs/pull/415666 (2025-06) - aliases = - lib.mapAttrs (name: lib.warn "`formats.${name}` is deprecated; use `lib.types.${name}` instead.") - { - inherit - attrsOf - bool - coercedTo - either - float - int - listOf - luaInline - mkOptionType - nonEmptyListOf - nullOr - oneOf - path - str - ; - }; + allowAliases = pkgs.config.allowAliases or false; + aliasWarning = name: warn "`formats.${name}` is deprecated; use `lib.types.${name}` instead."; + aliases = mapAttrs aliasWarning { + inherit + attrsOf + bool + coercedTo + either + float + int + listOf + luaInline + mkOptionType + nonEmptyListOf + nullOr + oneOf + path + str + ; + }; in optionalAttrs allowAliases aliases // rec { From b3b4fccfea9e08d6d28ccda68c4f9c98cc42dec3 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Tue, 10 Jun 2025 16:37:54 -0700 Subject: [PATCH 3/3] doc: do-nothing change to trigger a nixpkgs-manual rebuild --- doc/doc-support/package.nix | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/doc/doc-support/package.nix b/doc/doc-support/package.nix index 023be3a3a116..aefc301ec81c 100644 --- a/doc/doc-support/package.nix +++ b/doc/doc-support/package.nix @@ -57,10 +57,8 @@ stdenvNoCC.mkDerivation ( substituteInPlace ./languages-frameworks/python.section.md \ --subst-var-by python-interpreter-table "$(<"${pythonInterpreterTable}")" - cat \ - ./functions/library.md.in \ - ${lib-docs}/index.md \ - > ./functions/library.md + cat ./functions/library.md.in ${lib-docs}/index.md > ./functions/library.md + substitute ./manual.md.in ./manual.md \ --replace-fail '@MANUAL_VERSION@' '${lib.version}'