2024-04-06 22:10:15 +00:00
|
|
|
{ pkgs ? import <nixpkgs> { } }:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
inherit (pkgs.lib) fileContents last splitString flatten remove;
|
|
|
|
inherit (builtins) map match;
|
|
|
|
in {
|
|
|
|
findKeyValue = regex: sourceFile:
|
|
|
|
let
|
2024-07-25 09:07:02 +00:00
|
|
|
linesFrom = file: splitString "\n" (fileContents file);
|
2024-04-06 22:10:15 +00:00
|
|
|
matching = regex: lines: map (line: match regex line) lines;
|
|
|
|
extractMatch = matches: last (flatten (remove null matches));
|
|
|
|
in
|
|
|
|
extractMatch (matching regex (linesFrom sourceFile));
|
|
|
|
}
|