{ config, pkgs, lib, flakeRoot, ... }: let username = config.defaultUser or "henrov"; homeDir = "/home/${username}"; wallpaperSrc = "${flakeRoot}/assets/traveldroid/Wallpapers"; wallpaperDst = "${homeDir}/Wallpapers"; scriptFile = "${wallpaperDst}/set-wallpapers-at-logon.sh"; in { ############################ # Systemwide packages ############################ environment.systemPackages = with pkgs; [ swww waypaper jq rsync ]; ############################ # User systemd service to start swww, sync wallpapers, and run the script ############################ systemd.user.services.wallpaperSync = { description = "Sync Wallpapers and run set-wallpapers-at-logon.sh"; wants = [ "graphical-session.target" ]; after = [ "graphical-session.target" ]; serviceConfig.Type = "oneshot"; { config, pkgs, lib, flakeRoot, ... }: let username = config.defaultUser or "henrov"; homeDir = "/home/${username}"; wallpaperSrc = "${flakeRoot}/assets/traveldroid/Wallpapers"; wallpaperDst = "${homeDir}/Wallpapers"; scriptFile = "${wallpaperDst}/set-wallpapers-at-logon.sh"; in { environment.systemPackages = with pkgs; [ swww waypaper jq rsync ]; systemd.user.services.wallpaperSync = { description = "Sync Wallpapers and run set-wallpapers-at-logon.sh"; wants = [ "graphical-session.target" ]; after = [ "graphical-session.target" ]; serviceConfig.Type = "oneshot"; # Use a proper shell script invocation serviceConfig.ExecStart = '' ${pkgs.bash}/bin/bash -c ' mkdir -p "${wallpaperDst}" rsync -avu --ignore-existing "${wallpaperSrc}/" "${wallpaperDst}/" rsync -avu "${wallpaperSrc}/" "${wallpaperDst}/" # Start swww if not running pgrep swww >/dev/null 2>&1 || swww & # Run the logon wallpaper script if executable if [ -x "${scriptFile}" ]; then "${scriptFile}" fi ' ''; ############################ # Timer to run the service every 15 minutes ############################ systemd.user.timers.wallpaperSyncTimer = { description = "Run wallpaperSync service every 15 minutes"; wantedBy = [ "timers.target" ]; timerConfig.OnBootSec = "1min"; timerConfig.OnUnitActiveSec = "15min"; timerConfig.Persistent = true; }; }