From a13e0a12b7b4bf28ff15ac4cb79fd4b16e0bf217 Mon Sep 17 00:00:00 2001 From: Ivan Trubach Date: Fri, 19 Jul 2024 11:31:24 +0300 Subject: [PATCH 1/3] lib/deprecated: alias mapAttrsFlatten to mapAttrsToList These functions have identical implementation except for argument names. --- lib/deprecated/misc.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/deprecated/misc.nix b/lib/deprecated/misc.nix index d556bccbec0b..0209dba43406 100644 --- a/lib/deprecated/misc.nix +++ b/lib/deprecated/misc.nix @@ -31,7 +31,7 @@ let toList ; - inherit (lib.attrsets) removeAttrs; + inherit (lib.attrsets) removeAttrs mapAttrsToList; # returns default if env var is not set maybeEnv = name: default: @@ -212,7 +212,8 @@ let else closePropagationSlow; # calls a function (f attr value ) for each record item. returns a list - mapAttrsFlatten = f: r: map (attr: f attr r.${attr}) (attrNames r); + # Renamed to lib.attrsets.mapAttrsToList. + mapAttrsFlatten = mapAttrsToList; # attribute set containing one attribute nvs = name: value: listToAttrs [ (nameValuePair name value) ]; From 7919709a2352effcb28542efe7b340a3369a57c4 Mon Sep 17 00:00:00 2001 From: Ivan Trubach Date: Fri, 19 Jul 2024 11:32:13 +0300 Subject: [PATCH 2/3] nixos/modules: use mapAttrsToList instead of mapAttrsFlatten --- nixos/modules/programs/bash/bash.nix | 2 +- nixos/modules/programs/fish.nix | 4 ++-- nixos/modules/programs/zsh/zsh.nix | 2 +- nixos/modules/services/networking/openvpn.nix | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nixos/modules/programs/bash/bash.nix b/nixos/modules/programs/bash/bash.nix index 4c06f0aad9f8..1ffa7fe56109 100644 --- a/nixos/modules/programs/bash/bash.nix +++ b/nixos/modules/programs/bash/bash.nix @@ -10,7 +10,7 @@ let cfg = config.programs.bash; bashAliases = builtins.concatStringsSep "\n" ( - lib.mapAttrsFlatten (k: v: "alias -- ${k}=${lib.escapeShellArg v}") + lib.mapAttrsToList (k: v: "alias -- ${k}=${lib.escapeShellArg v}") (lib.filterAttrs (k: v: v != null) cfg.shellAliases) ); diff --git a/nixos/modules/programs/fish.nix b/nixos/modules/programs/fish.nix index 5a6fdb9b5ec5..ef31a404bcb8 100644 --- a/nixos/modules/programs/fish.nix +++ b/nixos/modules/programs/fish.nix @@ -7,12 +7,12 @@ let cfg = config.programs.fish; fishAbbrs = lib.concatStringsSep "\n" ( - lib.mapAttrsFlatten (k: v: "abbr -ag ${k} ${lib.escapeShellArg v}") + lib.mapAttrsToList (k: v: "abbr -ag ${k} ${lib.escapeShellArg v}") cfg.shellAbbrs ); fishAliases = lib.concatStringsSep "\n" ( - lib.mapAttrsFlatten (k: v: "alias ${k} ${lib.escapeShellArg v}") + lib.mapAttrsToList (k: v: "alias ${k} ${lib.escapeShellArg v}") (lib.filterAttrs (k: v: v != null) cfg.shellAliases) ); diff --git a/nixos/modules/programs/zsh/zsh.nix b/nixos/modules/programs/zsh/zsh.nix index 35d2cf461056..820d8daf81f1 100644 --- a/nixos/modules/programs/zsh/zsh.nix +++ b/nixos/modules/programs/zsh/zsh.nix @@ -10,7 +10,7 @@ let opt = options.programs.zsh; zshAliases = builtins.concatStringsSep "\n" ( - lib.mapAttrsFlatten (k: v: "alias -- ${k}=${lib.escapeShellArg v}") + lib.mapAttrsToList (k: v: "alias -- ${k}=${lib.escapeShellArg v}") (lib.filterAttrs (k: v: v != null) cfg.shellAliases) ); diff --git a/nixos/modules/services/networking/openvpn.nix b/nixos/modules/services/networking/openvpn.nix index 4a00cdc64975..fba6d5e48f92 100644 --- a/nixos/modules/services/networking/openvpn.nix +++ b/nixos/modules/services/networking/openvpn.nix @@ -223,7 +223,7 @@ in config = mkIf (cfg.servers != { }) { - systemd.services = (listToAttrs (mapAttrsFlatten (name: value: nameValuePair "openvpn-${name}" (makeOpenVPNJob value name)) cfg.servers)) + systemd.services = (listToAttrs (mapAttrsToList (name: value: nameValuePair "openvpn-${name}" (makeOpenVPNJob value name)) cfg.servers)) // restartService; environment.systemPackages = [ openvpn ]; From b9c51260d0620ffb0ef59d09b85d1f9d7b979b8c Mon Sep 17 00:00:00 2001 From: Ivan Trubach Date: Wed, 24 Jul 2024 13:01:58 +0300 Subject: [PATCH 3/3] lib/deprecated: print deprecation warning for mapAttrsFlatten --- lib/deprecated/misc.nix | 4 ++-- nixos/doc/manual/release-notes/rl-2411.section.md | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/deprecated/misc.nix b/lib/deprecated/misc.nix index 0209dba43406..34d1c01ce811 100644 --- a/lib/deprecated/misc.nix +++ b/lib/deprecated/misc.nix @@ -29,6 +29,7 @@ let nameValuePair tail toList + warn ; inherit (lib.attrsets) removeAttrs mapAttrsToList; @@ -212,8 +213,7 @@ let else closePropagationSlow; # calls a function (f attr value ) for each record item. returns a list - # Renamed to lib.attrsets.mapAttrsToList. - mapAttrsFlatten = mapAttrsToList; + mapAttrsFlatten = warn "lib.misc.mapAttrsFlatten is deprecated, please use lib.attrsets.mapAttrsToList instead." mapAttrsToList; # attribute set containing one attribute nvs = name: value: listToAttrs [ (nameValuePair name value) ]; diff --git a/nixos/doc/manual/release-notes/rl-2411.section.md b/nixos/doc/manual/release-notes/rl-2411.section.md index 96cc4301851d..cd51118dd160 100644 --- a/nixos/doc/manual/release-notes/rl-2411.section.md +++ b/nixos/doc/manual/release-notes/rl-2411.section.md @@ -240,6 +240,8 @@ - [`lib.options.mkPackageOptionMD`](https://nixos.org/manual/nixpkgs/unstable#function-library-lib.options.mkPackageOptionMD) is now obsolete; use the identical [`lib.options.mkPackageOption`](https://nixos.org/manual/nixpkgs/unstable#function-library-lib.options.mkPackageOption) instead. +- `lib.misc.mapAttrsFlatten` is now formally deprecated and will be removed in future releases; use the identical [`lib.attrsets.mapAttrsToList`](https://nixos.org/manual/nixpkgs/unstable#function-library-lib.attrsets.mapAttrsToList) instead. + - `nixosTests` now provide a working IPv6 setup for VLAN 1 by default. - To facilitate dependency injection, the `imgui` package now builds a static archive using vcpkg' CMake rules.