Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contrib/0/rfc169 proof/out #284107

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions experimental.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let
nixpkgs = import ./. {};
inherit (nixpkgs) cmus;
inherit (nixpkgs.lib) rfc0169Renamed;
in {
cmus2 = (rfc0169Renamed cmus.override) { with_alsa = false; };
cmus3 = (rfc0169Renamed cmus.override) { alsaSupport = false; };
}
6 changes: 3 additions & 3 deletions lib/customisation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -107,15 +107,15 @@ 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);
}
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);

Expand Down
2 changes: 2 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -166,5 +167,6 @@ let
nixType imap;
inherit (self.versions)
splitVersion;
inherit (self.rfc_0169) rfc0169Renamed;
});
in lib
6 changes: 6 additions & 0 deletions lib/rfc0169.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"with_alsa": [
"alsaSupport",
"withAlsa"
]
}
36 changes: 36 additions & 0 deletions lib/rfc_0169.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{ lib }:
let
inherit (lib) functionArgs isAttrs getAttr hasAttr mapAttrsToList warn;

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.
#
# 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');
}



4 changes: 2 additions & 2 deletions pkgs/applications/audio/cmus/default.nix
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading