I want to implement a systemd user service which determines my network environment. A NetworkManager hook is not sufficient in my case because it has to run in the user space. Therefore I can’t access the network-online.target
as well.
It’s planned that other services depend on this. Here’s a quick overview of what I’m trying to do.
In my configuration.nix I implemented it like this (the timer isn’t implemented yet):
systemd.user = {
targets = {
network-online = {
description = "Network interfaces are up";
wants = [ "if-up.service" ];
};
};
services = {
netenv = {
description = "Determine in which network environment the machine is when the network comes up";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
serviceConfig = {
Type = "exec";
Environment= "PATH=/run/current-system/sw/bin:$PATH";
ExecStart = "%h/bin/netenv.sh";
SyslogIdentifier="NetEnv";
};
};
if-up = {
description = "Monitor interface status";
wantedBy = [ "network-online.target" ];
before = [ "network-online.target" ];
serviceConfig = {
Type = "oneshot";
Environment= "PATH=/run/current-system/sw/bin:$PATH";
SyslogIdentifier="Interface-Watch";
RemainAfterExit="Yes";
};
script = "nm-online";
};
do-stuff = {
description = "Do something with the network connected";
requisite = [ "network-online.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "%h/bin/stuff.sh";
};
};
};
};
In theory, network-online.target
should be activated after I run systemctl --user start if-up.service
successfully and I think netenv.service
should start as well.
But nothing happens after if-up.service
completes. What am I missing? Is this even tested/supported in NixOS?