From 70ed2484600f4bbcd69c5acd2186e9ec49acceed Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Tue, 23 Jan 2024 19:03:35 -0500 Subject: [PATCH 1/5] cmus: Rename "alsaSupport" parameter to "with_alsa" according to RFC-169 --- pkgs/applications/audio/cmus/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/audio/cmus/default.nix b/pkgs/applications/audio/cmus/default.nix index 2ebeb55584895..18c7179cbff02 100644 --- a/pkgs/applications/audio/cmus/default.nix +++ b/pkgs/applications/audio/cmus/default.nix @@ -1,7 +1,7 @@ { config, lib, stdenv, fetchFromGitHub, fetchpatch, ncurses, pkg-config , libiconv, CoreAudio, AudioUnit, VideoToolbox -, alsaSupport ? stdenv.isLinux, alsa-lib ? null +, with_alsa ? stdenv.isLinux, alsa-lib ? null # simple fallback for everyone else , aoSupport ? !stdenv.isLinux, libao ? null , jackSupport ? false, libjack ? null @@ -53,7 +53,7 @@ let opts = [ # Audio output - (mkFlag alsaSupport "CONFIG_ALSA=y" alsa-lib) + (mkFlag with_alsa "CONFIG_ALSA=y" alsa-lib) (mkFlag aoSupport "CONFIG_AO=y" libao) (mkFlag jackSupport "CONFIG_JACK=y" libjack) (mkFlag samplerateSupport "CONFIG_SAMPLERATE=y" libsamplerate) From 8fa90c0c2096c25462fc6952935e64cf26cf5761 Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Tue, 23 Jan 2024 19:04:09 -0500 Subject: [PATCH 2/5] feat: Implement feature name backward compatibility --- experimental.nix | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 experimental.nix diff --git a/experimental.nix b/experimental.nix new file mode 100644 index 0000000000000..33af095305179 --- /dev/null +++ b/experimental.nix @@ -0,0 +1,46 @@ +let + nixpkgs = import ./. {}; + inherit (nixpkgs) lib; + + # TODO: Automate it. + BACKWARD = { + with_alsa = [ "alsaSupport" "withAlsa" ]; + }; + FORWARD = { + alsaSupport = "with_alsa"; + withAlsa = "with_alsa"; + }; + + victim = nixpkgs.cmus.override; + + oldArgs = lib.functionArgs victim; + + # Since we don't know what was the original deprecated name used by the + # package (if any, really), we have to extend original signature with all + # known deprecated names. + # + # Which means that if before it had "alsaSupport", now override can also be + # called with "withAlsa". And let's not bring what will happen if somebody + # provides both. Goal is to keep old code working, not preventing user from + # defying warnings and doing something stupid. + mkExtraArgs = name: value: + if lib.hasAttr name BACKWARD + then map (n: { name = n; value = value; }) (lib.getAttr name BACKWARD) + else []; + + patch = builtins.listToAttrs (builtins.concatLists (lib.mapAttrsToList mkExtraArgs oldArgs)); + newArgs = oldArgs // patch; + + newFunctor = args': + let f = name: value: + let renamed = lib.getAttr name FORWARD; + warning = "Feature parameter '" + name + "' is deprecated in favor of '" + renamed + "'."; + in if lib.hasAttr name FORWARD && lib.hasAttr (lib.getAttr name FORWARD) BACKWARD + then lib.warn warning { name = renamed; inherit value; } + else { inherit name value; }; + args = if builtins.isAttrs args' then builtins.listToAttrs (lib.mapAttrsToList f args') else args'; + in victim args; +in { + cmus2 = newFunctor { with_alsa = false; }; + cmus3 = newFunctor { alsaSupport = false; }; +} From a83ae11bbe945aa9e2b0ca1e4c0e27ed7a342ed0 Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Thu, 25 Jan 2024 08:24:24 -0500 Subject: [PATCH 3/5] feat: Add rfc0169 renaming logic into lib/ --- experimental.nix | 46 ++++------------------------------------------ lib/default.nix | 2 ++ lib/rfc_0169.nix | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 42 deletions(-) create mode 100644 lib/rfc_0169.nix diff --git a/experimental.nix b/experimental.nix index 33af095305179..ba2580c3ebab4 100644 --- a/experimental.nix +++ b/experimental.nix @@ -1,46 +1,8 @@ let nixpkgs = import ./. {}; - inherit (nixpkgs) lib; - - # TODO: Automate it. - BACKWARD = { - with_alsa = [ "alsaSupport" "withAlsa" ]; - }; - FORWARD = { - alsaSupport = "with_alsa"; - withAlsa = "with_alsa"; - }; - - victim = nixpkgs.cmus.override; - - oldArgs = lib.functionArgs victim; - - # Since we don't know what was the original deprecated name used by the - # package (if any, really), we have to extend original signature with all - # known deprecated names. - # - # Which means that if before it had "alsaSupport", now override can also be - # called with "withAlsa". And let's not bring what will happen if somebody - # provides both. Goal is to keep old code working, not preventing user from - # defying warnings and doing something stupid. - mkExtraArgs = name: value: - if lib.hasAttr name BACKWARD - then map (n: { name = n; value = value; }) (lib.getAttr name BACKWARD) - else []; - - patch = builtins.listToAttrs (builtins.concatLists (lib.mapAttrsToList mkExtraArgs oldArgs)); - newArgs = oldArgs // patch; - - newFunctor = args': - let f = name: value: - let renamed = lib.getAttr name FORWARD; - warning = "Feature parameter '" + name + "' is deprecated in favor of '" + renamed + "'."; - in if lib.hasAttr name FORWARD && lib.hasAttr (lib.getAttr name FORWARD) BACKWARD - then lib.warn warning { name = renamed; inherit value; } - else { inherit name value; }; - args = if builtins.isAttrs args' then builtins.listToAttrs (lib.mapAttrsToList f args') else args'; - in victim args; + inherit (nixpkgs) cmus; + inherit (nixpkgs.lib) rfc0169Renamed; in { - cmus2 = newFunctor { with_alsa = false; }; - cmus3 = newFunctor { alsaSupport = false; }; + cmus2 = (rfc0169Renamed cmus.override) { with_alsa = false; }; + cmus3 = (rfc0169Renamed cmus.override) { alsaSupport = false; }; } diff --git a/lib/default.nix b/lib/default.nix index f6c94ae91634f..16630a851e31e 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -63,6 +63,7 @@ let # linux kernel configuration kernel = callLibs ./kernel.nix; + rfc_0169 = callLibs ./rfc_0169.nix; inherit (builtins) add addErrorContext attrNames concatLists deepSeq elem elemAt filter genericClosure genList getAttr @@ -166,5 +167,6 @@ let nixType imap; inherit (self.versions) splitVersion; + inherit (self.rfc_0169) rfc0169Renamed; }); in lib diff --git a/lib/rfc_0169.nix b/lib/rfc_0169.nix new file mode 100644 index 0000000000000..1a0a2805f6746 --- /dev/null +++ b/lib/rfc_0169.nix @@ -0,0 +1,40 @@ +{ lib }: +let + inherit (lib) functionArgs isAttrs getAttr hasAttr mapAttrsToList warn; + # TODO: Automate it. + BACKWARD = { + with_alsa = [ "alsaSupport" "withAlsa" ]; + }; + FORWARD = { + alsaSupport = "with_alsa"; + withAlsa = "with_alsa"; + }; + # Since we don't know what was the original deprecated name used by the + # package (if any, really), we have to extend original signature with all + # known deprecated names. + # + # Which means that if before it had "alsaSupport", now override can also be + # called with "withAlsa". And let's not bring what will happen if somebody + # provides both. Goal is to keep old code working, not preventing user from + # defying warnings and doing something stupid. + mkExtraArgs = name: value: + if hasAttr name BACKWARD + then map (n: { name = n; value = value; }) (getAttr name BACKWARD) + else []; + renamePair = name: value: + let renamed = lib.getAttr name FORWARD; + warning = "Feature parameter '" + name + "' is deprecated in favor of '" + renamed + "'."; + in if hasAttr name FORWARD && hasAttr (getAttr name FORWARD) BACKWARD + then warn warning { name = renamed; inherit value; } + else { inherit name value; }; +in { + rfc0169Renamed = functor: + let oldArgs = functionArgs functor; + patch = builtins.listToAttrs (builtins.concatLists (mapAttrsToList mkExtraArgs oldArgs)); + in if patch == {} + then functor # nothing to do. + else args': functor (if isAttrs args' then builtins.listToAttrs (mapAttrsToList renamePair args') else args'); +} + + + From a1415d3f41152a71a7f7ade93d8e503f92825d7d Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Fri, 26 Jan 2024 16:22:01 -0500 Subject: [PATCH 4/5] feat: Include "rfc0169Renamed" into makeOverridable --- lib/customisation.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/customisation.nix b/lib/customisation.nix index 0b5cad71fddf4..64571d482ea29 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -7,7 +7,7 @@ let functionArgs isFunction mirrorFunctionArgs isAttrs setFunctionArgs optionalAttrs attrNames filter elemAt concatStringsSep sortOn take length filterAttrs optionalString flip pathIsDirectory head pipe isDerivation listToAttrs - mapAttrs seq flatten deepSeq warnIf isInOldestRelease extends + mapAttrs seq flatten deepSeq warnIf isInOldestRelease extends rfc0169Renamed ; inherit (lib.strings) levenshtein levenshteinAtMost; @@ -107,7 +107,7 @@ rec { in if isAttrs result then result // { - override = overrideArgs; + override = rfc0169Renamed overrideArgs; overrideDerivation = fdrv: overrideResult (x: overrideDerivation x fdrv); ${if result ? overrideAttrs then "overrideAttrs" else null} = fdrv: overrideResult (x: x.overrideAttrs fdrv); @@ -115,7 +115,7 @@ rec { else if isFunction result then # Transform the result into a functor while propagating its arguments setFunctionArgs result (functionArgs result) // { - override = overrideArgs; + override = rfc0169Renamed overrideArgs; } else result); From 3f655e709f3ea1fb909aa907fb24e1b4c5d5894c Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Sat, 27 Jan 2024 16:12:52 -0500 Subject: [PATCH 5/5] feat: Move renaming rules into separate json file --- lib/rfc0169.json | 6 ++++++ lib/rfc_0169.nix | 12 ++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 lib/rfc0169.json diff --git a/lib/rfc0169.json b/lib/rfc0169.json new file mode 100644 index 0000000000000..6da71702c1f58 --- /dev/null +++ b/lib/rfc0169.json @@ -0,0 +1,6 @@ +{ + "with_alsa": [ + "alsaSupport", + "withAlsa" + ] +} diff --git a/lib/rfc_0169.nix b/lib/rfc_0169.nix index 1a0a2805f6746..861bd0d581738 100644 --- a/lib/rfc_0169.nix +++ b/lib/rfc_0169.nix @@ -1,14 +1,10 @@ { lib }: let inherit (lib) functionArgs isAttrs getAttr hasAttr mapAttrsToList warn; - # TODO: Automate it. - BACKWARD = { - with_alsa = [ "alsaSupport" "withAlsa" ]; - }; - FORWARD = { - alsaSupport = "with_alsa"; - withAlsa = "with_alsa"; - }; + + BACKWARD = builtins.fromJSON (builtins.readFile ./rfc0169.json); + FORWARD = builtins.listToAttrs (builtins.concatLists (mapAttrsToList (n: map (x: { name = x; value = n; })) BACKWARD)); + # Since we don't know what was the original deprecated name used by the # package (if any, really), we have to extend original signature with all # known deprecated names.