Chris Stryczynski
Chris Stryczynski

Reputation: 33911

Nixos container with custom user systemd unit

I've defined the following container:

  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" ];
        };
      };
    };
  };

Essentially a test finder service defined. However, this does not seem to work according to the output from:

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

I thought perhaps these 'user' services don't run for the root user. But after adding a user and logging in, still no change.

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.

Why isn't this service working? Is it not supported in nixos containers?

Upvotes: 2

Views: 1373

Answers (1)

Robert Hensing
Robert Hensing

Reputation: 7369

nixos-container root-login does the bare minimum to give you a shell; nsenter and su

The command nixos-container login should work. That's backed by machinectl login, which can set things up properly so systemctl can do its job.

Upvotes: 1

Related Questions