summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2022-12-27 22:55:20 +0100
committerlassulus <lassulus@lassul.us>2022-12-27 22:55:20 +0100
commit97687ea0de4847a9c56cd58ac31f1c188d87b121 (patch)
tree5467b7c31c0de3c2ba2c7dd7388dfa66f267fe05 /lib
parent6b4abfdf4ae8858f2c58acc5d52da7a4a35e5905 (diff)
parent0d661dd94a6215d49397aabbaeaedab06a1fb66e (diff)
Merge remote-tracking branch 'ni/master'
Diffstat (limited to 'lib')
-rw-r--r--lib/default.nix26
-rw-r--r--lib/haskell.nix7
2 files changed, 32 insertions, 1 deletions
diff --git a/lib/default.nix b/lib/default.nix
index 149b97a..280f042 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -39,6 +39,8 @@ let
ne = x: y: x != y;
mod = x: y: x - y * (x / y);
+ on = b: u: x: y: b (u x) (u y);
+
genid = lib.genid_uint32; # TODO remove
genid_uint31 = x: ((lib.genid_uint32 x) + 16777216) / 2;
genid_uint32 = import ./genid.nix { inherit lib; };
@@ -185,6 +187,30 @@ let
in
filter (x: x != []) ([acc.chunk] ++ acc.chunks);
+ # Filter adjacent duplicate elements.
+ uniq = uniqBy eq;
+
+ # Filter adjacent duplicate elements determined via the given function.
+ uniqBy = cmp: let
+ f = a: s:
+ if length s == 0 then
+ []
+ else let
+ b = head s;
+ in
+ if cmp a b then
+ f b (tail s)
+ else
+ [b] ++ f b (tail s);
+ in
+ s:
+ if length s == 0 then
+ []
+ else let
+ b = head s;
+ in
+ [b] ++ f b (tail s);
+
warnOldVersion = oldName: newName:
if compareVersions oldName newName != -1 then
trace "Upstream `${oldName}' gets overridden by `${newName}'." newName
diff --git a/lib/haskell.nix b/lib/haskell.nix
index 4f0ee05..f87cfa7 100644
--- a/lib/haskell.nix
+++ b/lib/haskell.nix
@@ -39,7 +39,12 @@ rec {
in
if parse == null then
(pkgs.writeText name s).overrideAttrs (old: {
- dependencies = old.dependencies or [] ++ dependencies;
+ dependencies =
+ lib.uniq
+ (lib.sort (lib.on lib.lessThan (lib.getAttr "name"))
+ (filter
+ (lib.ne null)
+ (old.dependencies or [] ++ dependencies)));
})
else