Files
nixos/Droidnix/generated/modules/traveldroid/desktop/wallpaper.nix
T
2026-03-29 13:18:32 +00:00

58 lines
1.7 KiB
Nix

{ config, pkgs, lib, flakeRoot, ... }:
let
username = config.users.users."traveldroid".name or "traveldroid";
homeDir = "/home/${username}";
wallpaperSrc = "${flakeRoot}/assets/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 = "Start swww, sync Wallpapers and run set-wallpapers-at-logon.sh";
wants = [ "graphical-session.target" ];
after = [ "graphical-session.target" ];
serviceConfig.Type = "oneshot";
serviceConfig.ExecStart = ''
# Start swww daemon if not running
pgrep swww >/dev/null 2>&1 || swww &
# Ensure destination exists
mkdir -p ${wallpaperDst}
# Copy wallpapers: overwrite newer files, do not delete existing
rsync -au --ignore-existing ${wallpaperSrc}/ ${wallpaperDst}/
rsync -au ${wallpaperSrc}/ ${wallpaperDst}/
# Execute the logon wallpaper script
${scriptFile}
'';
serviceConfig.Restart = "on-failure";
};
############################
# 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"; # run soon after login
timerConfig.OnUnitActiveSec = "15min";
timerConfig.Persistent = true;
};
}