Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/services/blueman-applet.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ with lib;
};

config = mkIf config.services.blueman-applet.enable {
assertions = [
(hm.assertions.assertPlatform "services.blueman-applet" pkgs
platforms.linux)
];

systemd.user.services.blueman-applet = {
Unit = {
Description = "Blueman applet";
Expand Down
4 changes: 4 additions & 0 deletions modules/services/dunst.nix
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ in {

config = mkIf cfg.enable (mkMerge [
{
assertions = [
(hm.assertions.assertPlatform "services.dunst" pkgs platforms.linux)
];

home.packages = [ cfg.package ];

xdg.dataFile."dbus-1/services/org.knopwob.dunst.service".source =
Expand Down
4 changes: 4 additions & 0 deletions modules/services/gpg-agent.nix
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ in {
#
# directory.
{
assertions = [
(hm.assertions.assertPlatform "services.gpg-agent" pkgs platforms.linux)
];

systemd.user.services.gpg-agent = {
Unit = {
Description = "GnuPG cryptographic agent and passphrase cache";
Expand Down
10 changes: 10 additions & 0 deletions modules/services/kdeconnect.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ in {
(mkIf cfg.enable {
home.packages = [ package ];

assertions = [
(hm.assertions.assertPlatform "services.kdeconnect" pkgs
platforms.linux)
];

systemd.user.services.kdeconnect = {
Unit = {
Description =
Expand All @@ -46,6 +51,11 @@ in {
})

(mkIf cfg.indicator {
assertions = [
(hm.assertions.assertPlatform "services.kdeconnect" pkgs
platforms.linux)
];

systemd.user.services.kdeconnect-indicator = {
Unit = {
Description = "kdeconnect-indicator";
Expand Down
4 changes: 4 additions & 0 deletions modules/services/keepassx.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ with lib;
};

config = mkIf config.services.keepassx.enable {
assertions = [
(hm.assertions.assertPlatform "services.keepassx" pkgs platforms.linux)
];

systemd.user.services.keepassx = {
Unit = {
Description = "KeePassX password manager";
Expand Down
5 changes: 5 additions & 0 deletions modules/services/mpd-discord-rpc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ in {
};

config = mkIf cfg.enable {
assertions = [
(hm.assertions.assertPlatform "services.mpd-discord-rpc" pkgs
platforms.linux)
];

xdg.configFile."discord-rpc/config.toml".source = configFile;

systemd.user.services.mpd-discord-rpc = {
Expand Down
5 changes: 5 additions & 0 deletions modules/services/owncloud-client.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ with lib;
};

config = mkIf config.services.owncloud-client.enable {
assertions = [
(hm.assertions.assertPlatform "services.owncloud-client" pkgs
platforms.linux)
];

systemd.user.services.owncloud-client = {
Unit = {
Description = "Owncloud Client";
Expand Down
4 changes: 4 additions & 0 deletions modules/services/pasystray.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ with lib;
};

config = mkIf config.services.pasystray.enable {
assertions = [
(hm.assertions.assertPlatform "services.pasystray" pkgs platforms.linux)
];

systemd.user.services.pasystray = {
Unit = {
Description = "PulseAudio system tray";
Expand Down
5 changes: 5 additions & 0 deletions modules/services/picom.nix
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ in {
};

config = mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "services.picom" pkgs
lib.platforms.linux)
];

services.picom.settings = mkDefaultAttrs {
# fading
fading = cfg.fade;
Expand Down
5 changes: 5 additions & 0 deletions modules/services/random-background.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ in {

config = mkIf cfg.enable (mkMerge ([
{
assertions = [
(hm.assertions.assertPlatform "services.random-background" pkgs
platforms.linux)
];

systemd.user.services.random-background = {
Unit = {
Description = "Set random desktop background using feh";
Expand Down
5 changes: 5 additions & 0 deletions modules/services/stalonetray.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ in {

config = mkIf cfg.enable (mkMerge [
{
assertions = [
(hm.assertions.assertPlatform "services.stalonetray" pkgs
platforms.linux)
];

home.packages = [ cfg.package ];

systemd.user.services.stalonetray = {
Expand Down
4 changes: 4 additions & 0 deletions modules/services/swayidle.nix
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ in {
};

config = mkIf cfg.enable {
assertions = [
(hm.assertions.assertPlatform "services.swayidle" pkgs platforms.linux)
];

systemd.user.services.swayidle = {
Unit = {
Description = "Idle manager for Wayland";
Expand Down
10 changes: 10 additions & 0 deletions modules/services/syncthing.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ in {
})

(mkIf (isAttrs cfg.tray && cfg.tray.enable) {
assertions = [
(hm.assertions.assertPlatform "services.syncthing.tray" pkgs
platforms.linux)
];

systemd.user.services = {
${cfg.tray.package.pname} = {
Unit = {
Expand All @@ -118,6 +123,11 @@ in {

# deprecated
(mkIf (isBool cfg.tray && cfg.tray) {
assertions = [
(hm.assertions.assertPlatform "services.syncthing.tray" pkgs
platforms.linux)
];

systemd.user.services = {
"syncthingtray" = {
Unit = {
Expand Down
4 changes: 4 additions & 0 deletions modules/services/taffybar.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ in {
};

config = mkIf config.services.taffybar.enable {
assertions = [
(hm.assertions.assertPlatform "services.taffybar" pkgs platforms.linux)
];

systemd.user.services.taffybar = {
Unit = {
Description = "Taffybar desktop bar";
Expand Down
4 changes: 4 additions & 0 deletions modules/services/tahoe-lafs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ with lib;
};

config = mkIf config.services.tahoe-lafs.enable {
assertions = [
(hm.assertions.assertPlatform "services.tahoe-lafs" pkgs platforms.linux)
];

systemd.user.services.tahoe-lafs = {
Unit = { Description = "Tahoe-LAFS"; };

Expand Down
4 changes: 4 additions & 0 deletions modules/services/udiskie.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ in {
};

config = mkIf config.services.udiskie.enable {
assertions = [
(hm.assertions.assertPlatform "services.udiskie" pkgs platforms.linux)
];

xdg.configFile."udiskie/config.yml".source =
yaml.generate "udiskie-config.yml" (mergeSets [
{
Expand Down
156 changes: 63 additions & 93 deletions modules/systemd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ let
mkPathSafeName =
lib.replaceStrings [ "@" ":" "\\" "[" "]" ] [ "-" "-" "-" "" "" ];

enabled = cfg.services != { } # \
|| cfg.slices != { } # \
|| cfg.sockets != { } # \
|| cfg.targets != { } # \
|| cfg.timers != { } # \
|| cfg.paths != { } # \
|| cfg.mounts != { } # \
|| cfg.automounts != { } # \
|| cfg.sessionVariables != { };

toSystemdIni = lib.generators.toINI {
listsAsDuplicateKeys = true;
mkKeyValue = key: value:
Expand Down Expand Up @@ -239,92 +229,72 @@ in {
};
};

config = mkMerge [
{
assertions = [{
assertion = enabled -> pkgs.stdenv.isLinux;
message = let
names = lib.concatStringsSep ", " (lib.attrNames ( # \
cfg.services # \
// cfg.slices # \
// cfg.sockets # \
// cfg.targets # \
// cfg.timers # \
// cfg.paths # \
// cfg.mounts # \
// cfg.sessionVariables));
in "Must use Linux for modules that require systemd: " + names;
}];
}

# If we run under a Linux system we assume that systemd is
# available, in particular we assume that systemctl is in PATH.
# Do not install any user services if username is root.
(mkIf (pkgs.stdenv.isLinux && config.home.username != "root") {
xdg.configFile = mkMerge [
(lib.listToAttrs ((buildServices "service" cfg.services)
++ (buildServices "slice" cfg.slices)
++ (buildServices "socket" cfg.sockets)
++ (buildServices "target" cfg.targets)
++ (buildServices "timer" cfg.timers)
++ (buildServices "path" cfg.paths)
++ (buildServices "mount" cfg.mounts)
++ (buildServices "automount" cfg.automounts)))

sessionVariables
];

# Run systemd service reload if user is logged in. If we're
# running this from the NixOS module then XDG_RUNTIME_DIR is not
# set and systemd commands will fail. We'll therefore have to
# set it ourselves in that case.
home.activation.reloadSystemd = hm.dag.entryAfter [ "linkGeneration" ]
(let
cmd = {
suggest = ''
PATH=${dirOf cfg.systemctlPath}:$PATH \
bash ${./systemd-activate.sh} "''${oldGenPath=}" "$newGenPath"
'';
legacy = ''
PATH=${dirOf cfg.systemctlPath}:$PATH \
${pkgs.ruby}/bin/ruby ${./systemd-activate.rb} \
"''${oldGenPath=}" "$newGenPath" "${servicesStartTimeoutMs}"
'';
sd-switch = let
timeoutArg = if cfg.servicesStartTimeoutMs != 0 then
"--timeout " + servicesStartTimeoutMs
else
"";
in ''
${pkgs.sd-switch}/bin/sd-switch \
''${DRY_RUN:+--dry-run} $VERBOSE_ARG ${timeoutArg} \
''${oldGenPath:+--old-units $oldGenPath/home-files/.config/systemd/user} \
--new-units $newGenPath/home-files/.config/systemd/user
'';
};
# If we run under a Linux system we assume that systemd is
# available, in particular we assume that systemctl is in PATH.
# Do not install any user services if username is root.
config = mkIf (pkgs.stdenv.isLinux && config.home.username != "root") {
xdg.configFile = mkMerge [
(lib.listToAttrs ((buildServices "service" cfg.services)
++ (buildServices "slice" cfg.slices)
++ (buildServices "socket" cfg.sockets)
++ (buildServices "target" cfg.targets)
++ (buildServices "timer" cfg.timers)
++ (buildServices "path" cfg.paths)
++ (buildServices "mount" cfg.mounts)
++ (buildServices "automount" cfg.automounts)))

sessionVariables
];

# Run systemd service reload if user is logged in. If we're
# running this from the NixOS module then XDG_RUNTIME_DIR is not
# set and systemd commands will fail. We'll therefore have to
# set it ourselves in that case.
home.activation.reloadSystemd = hm.dag.entryAfter [ "linkGeneration" ] (let
cmd = {
suggest = ''
PATH=${dirOf cfg.systemctlPath}:$PATH \
bash ${./systemd-activate.sh} "''${oldGenPath=}" "$newGenPath"
'';
legacy = ''
PATH=${dirOf cfg.systemctlPath}:$PATH \
${pkgs.ruby}/bin/ruby ${./systemd-activate.rb} \
"''${oldGenPath=}" "$newGenPath" "${servicesStartTimeoutMs}"
'';
sd-switch = let
timeoutArg = if cfg.servicesStartTimeoutMs != 0 then
"--timeout " + servicesStartTimeoutMs
else
"";
in ''
${pkgs.sd-switch}/bin/sd-switch \
''${DRY_RUN:+--dry-run} $VERBOSE_ARG ${timeoutArg} \
''${oldGenPath:+--old-units $oldGenPath/home-files/.config/systemd/user} \
--new-units $newGenPath/home-files/.config/systemd/user
'';
};

ensureRuntimeDir =
"XDG_RUNTIME_DIR=\${XDG_RUNTIME_DIR:-/run/user/$(id -u)}";
ensureRuntimeDir =
"XDG_RUNTIME_DIR=\${XDG_RUNTIME_DIR:-/run/user/$(id -u)}";

systemctl = "${ensureRuntimeDir} ${cfg.systemctlPath}";
in ''
systemdStatus=$(${systemctl} --user is-system-running 2>&1 || true)
systemctl = "${ensureRuntimeDir} ${cfg.systemctlPath}";
in ''
systemdStatus=$(${systemctl} --user is-system-running 2>&1 || true)

if [[ $systemdStatus == 'running' || $systemdStatus == 'degraded' ]]; then
if [[ $systemdStatus == 'degraded' ]]; then
warnEcho "The user systemd session is degraded:"
${systemctl} --user --no-pager --state=failed
warnEcho "Attempting to reload services anyway..."
fi
if [[ $systemdStatus == 'running' || $systemdStatus == 'degraded' ]]; then
if [[ $systemdStatus == 'degraded' ]]; then
warnEcho "The user systemd session is degraded:"
${systemctl} --user --no-pager --state=failed
warnEcho "Attempting to reload services anyway..."
fi

${ensureRuntimeDir} \
${getAttr cfg.startServices cmd}
else
echo "User systemd daemon not running. Skipping reload."
fi
${ensureRuntimeDir} \
${getAttr cfg.startServices cmd}
else
echo "User systemd daemon not running. Skipping reload."
fi

unset systemdStatus
'');
})
];
unset systemdStatus
'');
};
}