From 377ad0ea6efe164bf586836768e97035fc820d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=E2=80=9CNiols=E2=80=9D=20Jeannerod?= Date: Fri, 13 Dec 2024 12:19:26 +0100 Subject: [PATCH] Optionally remove `.pub` suffix from file names --- keys/default.nix | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/keys/default.nix b/keys/default.nix index 3bc08d1..9c1a2bd 100644 --- a/keys/default.nix +++ b/keys/default.nix @@ -1,14 +1,30 @@ let inherit (builtins) + attrValues elemAt + foldl' mapAttrs match readDir readFile ; + ## `mergeAttrs` and `concatMapAttrs` are in `lib.trivial` and `lib.attrsets`, + ## but we would rather avoid a dependency in nixpkgs for this file. + mergeAttrs = x: y: x // y; + concatMapAttrs = f: v: foldl' mergeAttrs { } (attrValues (mapAttrs f v)); + removePubSuffix = + s: + let + maybeMatch = match "(.*)\.pub" s; + in + if maybeMatch == null then s else elemAt maybeMatch 0; removeTrailingWhitespace = s: elemAt (match "(.*[^[:space:]])[[:space:]]*" s) 0; + collectKeys = - dir: mapAttrs (name: _: removeTrailingWhitespace (readFile (dir + "/${name}"))) (readDir dir); + dir: + concatMapAttrs (name: _: { + "${removePubSuffix name}" = removeTrailingWhitespace (readFile (dir + "/${name}")); + }) (readDir dir); in { contributors = collectKeys ./contributors;