14 lines
384 B
Nix
14 lines
384 B
Nix
|
{ lib }:
|
||
|
{
|
||
|
template = file: newPath: replacements:
|
||
|
let
|
||
|
templatePath = newPath + ".template";
|
||
|
sedPatterns = lib.strings.concatStringsSep " " (lib.attrsets.mapAttrsToList (from: to: "-e \"s|${from}|${to}|\"") replacements);
|
||
|
in
|
||
|
''
|
||
|
ln -fs ${file} ${templatePath}
|
||
|
rm ${newPath} || :
|
||
|
sed ${sedPatterns} ${templatePath} > ${newPath}
|
||
|
'';
|
||
|
}
|