我有一个长字符串,我想提取到一个单独的文件。
prepare = lib.hm.dag.entryAfter ["writeBoundary"] '' very long script with ${...} '';我可以用builtins.readFile来阅读它,但它并不能取代${...}的零位持有者。
如何从文件中读取字符串并解析其中的nix变量?
发布于 2021-06-14 07:33:03
您可以使用substitute系列bash函数(参见Nixpkgs手册),也可以使用substituteAll Nix函数,该函数生成执行替换的派生。
substituteAll { src = ./sample.sh; inherit bash; hi = hello; }sample.sh
#!@bash@/bin/bash
@hi@结果:
$ nix repl <nixpkgs>
nix-repl> substituteAll { src = ./sample.sh; inherit bash; hi = hello; }
«derivation /nix/store/7klv763a0ipgvwf3j84aazkzx2d5rljz-sample.sh.drv»
nix-repl> :b substituteAll { src = ./sample.sh; inherit bash; hi = hello; }
this derivation produced the following outputs:
out -> /nix/store/v03hpzw9ykrbyqpmalnijnyibq3waqhw-sample.sh
nix-repl> /nix/store/v03hpzw9ykrbyqpmalnijnyibq3waqhw-sample.sh
#!/nix/store/a4yw1svqqk4d8lhwinn9xp847zz9gfma-bash-4.4-p23/bin/bash
/nix/store/jmmw0d3nmklwafcwylvrjb9v69wrbcxf-hello-2.10https://stackoverflow.com/questions/67963396
复制相似问题