我有一个很长的字符串,我想将其提取到一个单独的文件中。
prepare = lib.hm.dag.entryAfter ["writeBoundary"] '' very long script with ${...} '';
Run Code Online (Sandbox Code Playgroud)
我可以用它来阅读它builtins.readFile,但它不能取代${...}nix 占位符。
如何从文件中读取字符串并解析其中的 nix 变量?
您可以使用substitutebash 函数系列(请参阅Nixpkgs 手册)或使用substituteAllNix 函数来生成执行替换的推导。
substituteAll { src = ./sample.sh; inherit bash; hi = hello; }\nRun Code Online (Sandbox Code Playgroud)\nsample.sh:
#!@bash@/bin/bash\n@hi@\nRun Code Online (Sandbox Code Playgroud)\n结果:
\n$ nix repl <nixpkgs>\n\nnix-repl> substituteAll { src = ./sample.sh; inherit bash; hi = hello; }\n\xc2\xabderivation /nix/store/7klv763a0ipgvwf3j84aazkzx2d5rljz-sample.sh.drv\xc2\xbb\n\nnix-repl> :b substituteAll { src = ./sample.sh; inherit bash; hi = hello; }\n\nthis derivation produced the following outputs:\n out -> /nix/store/v03hpzw9ykrbyqpmalnijnyibq3waqhw-sample.sh\n\nnix-repl> \nRun Code Online (Sandbox Code Playgroud)\n/nix/store/v03hpzw9ykrbyqpmalnijnyibq3waqhw-sample.sh:
#!/nix/store/a4yw1svqqk4d8lhwinn9xp847zz9gfma-bash-4.4-p23/bin/bash\n/nix/store/jmmw0d3nmklwafcwylvrjb9v69wrbcxf-hello-2.10\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
4110 次 |
| 最近记录: |