【发布时间】:2021-11-20 02:38:33
【问题描述】:
我尝试创建一个简单的模板服务:
systemd.services."myuser@" = {
script = "echo Hi, %u";
};
很遗憾,%u 模板没有展开:
$ sudo systemctl start myuser@foo
$ journalctl --catalog --output=cat --unit myuser@foo
Started myuser@foo.service.
Hi, %u
myuser@foo.service: Succeeded.
这是因为 Nix 将模板字符串包装在脚本中:
$ systemctl status --lines=0 myuser@foo
● myuser@foo.service
Loaded: loaded (/nix/store/wiq9v9kgj78yd3h4dc1rgx0jgdxizrp4-unit-myuser-.service/myuser@.service; static)
Active: inactive (dead)
$ systemctl show --property ExecStart myuser@foo.service
ExecStart={ path=/nix/store/d6n5gj0llxi2sqhsb87rz7rl0l2rs4x7-unit-script-myuser_-start/bin/myuser_-start ; argv[]=/nix/store/d6n5gj0llxi2sqhsb87rz7rl0l2rs4x7-unit-script-myuser_-start/bin/myuser_-start ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }
$ cat /nix/store/d6n5gj0llxi2sqhsb87rz7rl0l2rs4x7-unit-script-myuser_-start/bin/myuser_-start
#!/nix/store/wv35g5lff84rray15zlzarcqi9fxzz84-bash-4.4-p23/bin/bash -e
echo Hi, %u
在 NixOS 中创建模板服务的规范方法是什么?我需要覆盖ExecStart,还是有更优雅的解决方案?
【问题讨论】: