lib.haskell.substitutePkgs: add dependencies

This commit is contained in:
tv 2022-03-22 00:55:53 +01:00
parent 2ad9dc3617
commit 44ec31fe02

View File

@ -9,19 +9,14 @@ rec {
# "${pkgs.bar}/bin/foo" for each {-pkg:bar-}"foo". # "${pkgs.bar}/bin/foo" for each {-pkg:bar-}"foo".
# If a package doesn't exist, a warning gets printed. # If a package doesn't exist, a warning gets printed.
substitutePkgs = name: { callsite ? null, pkgs, path }: substitutePkgs = name: { callsite ? null, pkgs, path }:
pkgs.writeText name (substitutePkgs' { let
inherit pkgs;
sourceDescription = sourceDescription =
if callsite != null then if callsite != null then
"${name} in ${toString callsite}" "${name} in ${toString callsite}"
else else
"${name} from ${toString path}"; "${name} from ${toString path}";
text = readFile path;
});
substitutePkgs' = { pkgs, sourceDescription, text }: f = dependencies: s:
let
f = s:
let let
parse = match "(.*)([{]-pkg(:([^}]+))?-[}]\"([^\"]+)\")(.*)" s; parse = match "(.*)([{]-pkg(:([^}]+))?-[}]\"([^\"]+)\")(.*)" s;
prefix = elemAt parse 0; prefix = elemAt parse 0;
@ -43,9 +38,12 @@ rec {
exename; exename;
in in
if parse == null then if parse == null then
s (pkgs.writeText name s).overrideAttrs (old: {
dependencies = old.dependencies or [] ++ dependencies;
})
else else
f (prefix + toJSON substitute + suffix); f (dependencies ++ [pkg]) (prefix + toJSON substitute + suffix);
in in
f text; f [] (readFile path);
} }