system-manager icon indicating copy to clipboard operation
system-manager copied to clipboard

How to translate unit file to system-manager config?

Open jordan-bravo opened this issue 3 months ago • 0 comments

Describe the bug

This is not a bug but rather a question on usage.

My question is where to put the specific settings for a unit file. For example, I am trying to re-create the systemd service that is created when Tailscale is installed with apt.

On Ubuntu 24.04, sudo apt install tailscale creates the following unit file: /etc/systemd/system/multi-user.target.wants/tailscaled.service

[Unit]
Description=Tailscale node agent
Documentation=https://tailscale.com/kb/
Wants=network-pre.target
After=network-pre.target NetworkManager.service systemd-resolved.service

[Service]
EnvironmentFile=/etc/default/tailscaled
ExecStart=/usr/sbin/tailscaled --state=/var/lib/tailscale/tailscaled.state --socket=/run/tailscale/tailscaled.sock --port=${PORT} $FLAGS
ExecStopPost=/usr/sbin/tailscaled --cleanup

Restart=on-failure

RuntimeDirectory=tailscale
RuntimeDirectoryMode=0755
StateDirectory=tailscale
StateDirectoryMode=0700
CacheDirectory=tailscale
CacheDirectoryMode=0750
Type=notify

[Install]
WantedBy=multi-user.target

My System-Manager default.nix file looks like this so far, but I'm not sure how to add the rest:

{ config, lib, pkgs, ... }:

{
  config = {
    nixpkgs.hostPlatform = "x86_64-linux";

    environment = {
      etc = {
       # What goes here?
      };
      systemPackages = [
        pkgs.hello
        pkgs.tailscale
      ];
    };

    systemd.services = {
      tailscaled = {
        enable = true;
        description = "Tailscale node agent";
        documentation = "https://tailscale.com/kb/";
        wants = [ "network-pre.target" ];
        after = [
          "network-pre.target"
          "NetworkManager.service"
          "systemd-resolved.service"
        ];
        serviceConfig = {
          Type = "notify";
        };
        wantedBy = [ "multi-user.target" ];
      };
    };
  };
}

Where would I add (and what is the syntax for) the following parts of the unit file?

  • EnvironmentFile=/etc/default/tailscaled
  • ExecStart=/usr/sbin/tailscaled --state=/var/lib/tailscale/tailscaled.state --socket=/run/tailscale/tailscaled.sock --port=${PORT} $FLAGS
  • ExecStopPost=/usr/sbin/tailscaled --cleanup
  • Restart=on-failure
  • RuntimeDirectory=tailscale
  • RuntimeDirectoryMode=0755
  • StateDirectory=tailscale
  • StateDirectoryMode=0700
  • CacheDirectory=tailscale
  • CacheDirectoryMode=0750

I tried looking through the source code of system-manager to get some hints but to be honest I'm struggling to find them.

To Reproduce

Steps to reproduce the behavior:

  1. Attempt to create Tailscale unit file.
  2. Get stumped.

Expected behavior

Would like some help or documentation on where each setting goes.

System information

Ubuntu 24.04

Additional context

I will also create an issue to suggest a discussion section for the repo so these kinds of questions don't clutter up the "Issues" section.

jordan-bravo avatar Apr 30 '24 20:04 jordan-bravo