Skip to content

Commit

Permalink
attribute-ordering: Fix with inherited attributes
Browse files Browse the repository at this point in the history
Prior to Nix 2.21, all attributes within a single `inherit` block would have the same column and line.
This is no longer the case so we can drop the workaround.
  • Loading branch information
jtojnar committed Dec 22, 2024
1 parent 7e066b1 commit 56e8d63
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions overlays/attribute-ordering.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ let
checkDerivation = drvArgs: drv:
let
getAttrPos = attr: (builtins.unsafeGetAttrPos attr drvArgs);
getAttrLine = attr: (getAttrPos attr).line;

drvAttrs = lib.pipe drvArgs [
builtins.attrNames
# Certain functions like mapAttrs can produce attributes without associated position.
(builtins.filter (attr: getAttrPos attr != null))
(builtins.sort (a: b: getAttrLine a < getAttrLine b))
(builtins.sort (aName: bName: let a = getAttrPos aName; b = getAttrPos bName; in a.line < b.line || (a.line == b.line && a.column < b.column)))
];

knownDrvAttrs = builtins.filter (attr: preferredOrdering ? "${attr}") drvAttrs;
Expand All @@ -45,11 +44,7 @@ let
sameGroup = fstInfo.group == sndInfo.group;
in {
name = "attribute-ordering";
cond =
fstInfo.order > sndInfo.order &&
# Inherited attributes all have the same position so sort will keep them in alphabetical order returned by attrNames.
# This means we will not be able to detect if they are out of order and have to skip them.
getAttrPos fst != getAttrPos snd;
cond = fstInfo.order > sndInfo.order;
msg = ''
The ${lib.optionalString (sndInfo.group != null && !sameGroup) "${sndInfo.group}, including the "}attribute “${snd}” should preferably come before ${lib.optionalString (fstInfo.group != null && !sameGroup) "${fstInfo.group}’ "}${fst}” attribute ${lib.optionalString (sndInfo.group != null && sameGroup) "among ${sndInfo.group} "}in the expression.
'';
Expand Down

0 comments on commit 56e8d63

Please sign in to comment.