{ config, pkgs, flakeRoot, ... }: let username = config.defaultUser or "henrov"; homeDir = "/home/${username}"; scriptFile = "${homeDir}/Wallpapers/set-wallpapers-at-logon.sh"; in { ############################ # System-wide packages ############################ environment.systemPackages = with pkgs; [ swww waypaper jq rsync ]; ############################ # swww daemon for the user ############################ systemd.user.services.swwwDaemon = { description = "swww wallpaper daemon"; after = [ "graphical-session.target" ]; wantedBy = [ "default.target" ]; serviceConfig = { ExecStart = "${pkgs.swww}/bin/swww daemon"; Restart = "always"; Type = "simple"; }; }; ############################ # User service: run the wallpaper script ############################ systemd.user.services.wallpaperSync = { description = "Run set-wallpapers-at-logon.sh"; wantedBy = [ "default.target" ]; serviceConfig = { Type = "oneshot"; # Ensure Nix binaries are in PATH Environment = "PATH=/run/current-system/sw/bin:/usr/bin:/bin"; ExecStart = "${pkgs.bash}/bin/bash ${scriptFile}"; Restart = "on-failure"; }; }; ############################ # Timer: run service every 15 minutes ############################ systemd.user.timers.wallpaperSyncTimer = { description = "Run wallpaperSync service every 15 minutes"; wantedBy = [ "timers.target" ]; timerConfig.OnUnitActiveSec = "15min"; timerConfig.Persistent = true; }; ############################ # Run the script at login ############################ systemd.user.services.wallpaperSyncLogin = { description = "Run wallpaperSync at login"; wantedBy = [ "default.target" ]; serviceConfig = { Type = "oneshot"; Environment = "PATH=/run/current-system/sw/bin:/usr/bin:/bin"; ExecStart = "${pkgs.bash}/bin/bash ${scriptFile}"; }; }; }