diff --git a/modules/services/blueman-applet.nix b/modules/services/blueman-applet.nix index 460dd1677c5d..d81db1dbb58f 100644 --- a/modules/services/blueman-applet.nix +++ b/modules/services/blueman-applet.nix @@ -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"; diff --git a/modules/services/dunst.nix b/modules/services/dunst.nix index b98b645e42ae..8606e24813bc 100644 --- a/modules/services/dunst.nix +++ b/modules/services/dunst.nix @@ -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 = diff --git a/modules/services/gpg-agent.nix b/modules/services/gpg-agent.nix index fb59d70924cf..39e93669fb49 100644 --- a/modules/services/gpg-agent.nix +++ b/modules/services/gpg-agent.nix @@ -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"; diff --git a/modules/services/kdeconnect.nix b/modules/services/kdeconnect.nix index 87c57c4e9b6b..0c6aac31e80f 100644 --- a/modules/services/kdeconnect.nix +++ b/modules/services/kdeconnect.nix @@ -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 = @@ -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"; diff --git a/modules/services/keepassx.nix b/modules/services/keepassx.nix index dc37066e20ce..7f85823619d8 100644 --- a/modules/services/keepassx.nix +++ b/modules/services/keepassx.nix @@ -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"; diff --git a/modules/services/mpd-discord-rpc.nix b/modules/services/mpd-discord-rpc.nix index 5e7a6664b8a8..50bc824b095b 100644 --- a/modules/services/mpd-discord-rpc.nix +++ b/modules/services/mpd-discord-rpc.nix @@ -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 = { diff --git a/modules/services/owncloud-client.nix b/modules/services/owncloud-client.nix index d55d8ffa2a41..4eeafcf0a74c 100644 --- a/modules/services/owncloud-client.nix +++ b/modules/services/owncloud-client.nix @@ -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"; diff --git a/modules/services/pasystray.nix b/modules/services/pasystray.nix index 15c951e137ef..32922ad0fac3 100644 --- a/modules/services/pasystray.nix +++ b/modules/services/pasystray.nix @@ -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"; diff --git a/modules/services/picom.nix b/modules/services/picom.nix index f4f8edb4301a..66f707c0a13c 100644 --- a/modules/services/picom.nix +++ b/modules/services/picom.nix @@ -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; diff --git a/modules/services/random-background.nix b/modules/services/random-background.nix index 9deee8deb5c1..16c869a9c52d 100644 --- a/modules/services/random-background.nix +++ b/modules/services/random-background.nix @@ -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"; diff --git a/modules/services/stalonetray.nix b/modules/services/stalonetray.nix index 93fff3e7b5fe..172d6dd9dcf6 100644 --- a/modules/services/stalonetray.nix +++ b/modules/services/stalonetray.nix @@ -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 = { diff --git a/modules/services/swayidle.nix b/modules/services/swayidle.nix index db54f9e27f79..6e8b55cb830d 100644 --- a/modules/services/swayidle.nix +++ b/modules/services/swayidle.nix @@ -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"; diff --git a/modules/services/syncthing.nix b/modules/services/syncthing.nix index 2f9cecdb4f9b..bbe9f86609ae 100644 --- a/modules/services/syncthing.nix +++ b/modules/services/syncthing.nix @@ -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 = { @@ -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 = { diff --git a/modules/services/taffybar.nix b/modules/services/taffybar.nix index 088827b9554a..42ca5f7bb785 100644 --- a/modules/services/taffybar.nix +++ b/modules/services/taffybar.nix @@ -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"; diff --git a/modules/services/tahoe-lafs.nix b/modules/services/tahoe-lafs.nix index 742b779b270f..105ef3d03b28 100644 --- a/modules/services/tahoe-lafs.nix +++ b/modules/services/tahoe-lafs.nix @@ -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"; }; diff --git a/modules/services/udiskie.nix b/modules/services/udiskie.nix index d53d7cc8ab54..562297963d0b 100644 --- a/modules/services/udiskie.nix +++ b/modules/services/udiskie.nix @@ -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 [ { diff --git a/modules/systemd.nix b/modules/systemd.nix index e4c36ae42051..456b22fd1640 100644 --- a/modules/systemd.nix +++ b/modules/systemd.nix @@ -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: @@ -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 + ''); + }; }