具有自定义用户 systemd 单元的 Nixos 容器
Nixos container with custom user systemd unit
我定义了以下容器:
containers.abc123 = {
config = { config, pkgs, ... }:
{
systemd.user.services = {
finder = {
description = "finder";
enable = true;
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.coreutils}/bin/mkdir /tmp/hello";
Restart = "always";
RestartSec = 50;
};
wantedBy = [ "default.target" ];
};
};
};
};
本质上是一个测试 finder
定义的服务。但是,根据以下输出,这似乎不起作用:
sudo nixos-container run abc123 -- systemctl status finder
Unit finder.service could not be found.
sudo nixos-container run abc123 -- systemctl status --user finder
Failed to connect to bus: No such file or directory
我认为这些 'user' 服务可能不会 运行 root 用户。但是添加用户并登录后,还是没有任何变化
sudo nixos-container root-login abc123
[root@abc123:~]# systemctl status --user finder
Failed to connect to bus: No such file or directory
[root@abc123:~]# su test123
[test123@abc123:/root]$ systemctl status --user finder
Failed to connect to bus: No such file or directory
[test123@abc123:/root]$ systemctl status finder
Unit finder.service could not be found.
为什么这项服务不起作用? nixos 容器不支持它吗?
nixos-container root-login
尽最大努力给你 shell; nsenter
and su
命令 nixos-container login
应该有效。这得到了 machinectl login
的支持,它可以正确设置,因此 systemctl
可以完成它的工作。
我定义了以下容器:
containers.abc123 = {
config = { config, pkgs, ... }:
{
systemd.user.services = {
finder = {
description = "finder";
enable = true;
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.coreutils}/bin/mkdir /tmp/hello";
Restart = "always";
RestartSec = 50;
};
wantedBy = [ "default.target" ];
};
};
};
};
本质上是一个测试 finder
定义的服务。但是,根据以下输出,这似乎不起作用:
sudo nixos-container run abc123 -- systemctl status finder
Unit finder.service could not be found.
sudo nixos-container run abc123 -- systemctl status --user finder
Failed to connect to bus: No such file or directory
我认为这些 'user' 服务可能不会 运行 root 用户。但是添加用户并登录后,还是没有任何变化
sudo nixos-container root-login abc123
[root@abc123:~]# systemctl status --user finder
Failed to connect to bus: No such file or directory
[root@abc123:~]# su test123
[test123@abc123:/root]$ systemctl status --user finder
Failed to connect to bus: No such file or directory
[test123@abc123:/root]$ systemctl status finder
Unit finder.service could not be found.
为什么这项服务不起作用? nixos 容器不支持它吗?
nixos-container root-login
尽最大努力给你 shell; nsenter
and su
命令 nixos-container login
应该有效。这得到了 machinectl login
的支持,它可以正确设置,因此 systemctl
可以完成它的工作。