Regenerated
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
{ config, pkgs, flakeRoot, ... }:
|
||||
{ config, pkgs, lib, flakeRoot, ... }:
|
||||
|
||||
let
|
||||
username = config.defaultUser or "henrov";
|
||||
homeDir = "/home/${username}";
|
||||
scriptFile = "${homeDir}/Wallpapers/set-wallpapers-at-logon.sh";
|
||||
socketFile = "/run/user/${config.users.users.${username}.uid or 1000}/wayland-1-swww-daemon.1.sock";
|
||||
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
|
||||
{
|
||||
############################
|
||||
# System-wide packages
|
||||
# Systemwide packages
|
||||
############################
|
||||
environment.systemPackages = with pkgs; [
|
||||
swww
|
||||
@@ -18,67 +19,41 @@ in
|
||||
];
|
||||
|
||||
############################
|
||||
# swww daemon for the user
|
||||
# Ensure swww daemon runs
|
||||
############################
|
||||
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";
|
||||
};
|
||||
};
|
||||
services.swww.enable = true;
|
||||
|
||||
############################
|
||||
# Run the wallpaper script at login
|
||||
############################
|
||||
systemd.user.services.wallpaperSyncLogin = {
|
||||
description = "Run wallpaper script at login";
|
||||
wantedBy = [ "default.target" ];
|
||||
after = [ "swwwDaemon.service" ];
|
||||
requires = [ "swwwDaemon.service" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
Environment = "PATH=/run/current-system/sw/bin:/usr/bin:/bin";
|
||||
# Wait for the swww socket
|
||||
ExecStartPre = ''
|
||||
for i in $(seq 1 10); do
|
||||
[ -S ${socketFile} ] && exit 0
|
||||
sleep 0.5
|
||||
done
|
||||
echo "swww daemon socket not found, aborting"
|
||||
exit 1
|
||||
'';
|
||||
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 every 15 min
|
||||
# User systemd service to sync wallpapers and run script
|
||||
############################
|
||||
systemd.user.services.wallpaperSync = {
|
||||
description = "Run wallpaper script periodically";
|
||||
wantedBy = [ "default.target" ];
|
||||
after = [ "swwwDaemon.service" ];
|
||||
requires = [ "swwwDaemon.service" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
Environment = "PATH=/run/current-system/sw/bin:/usr/bin:/bin";
|
||||
ExecStart = "${pkgs.bash}/bin/bash ${scriptFile}";
|
||||
Restart = "on-failure";
|
||||
};
|
||||
description = "Sync Wallpapers and run set-wallpapers-at-logon.sh";
|
||||
wants = [ "graphical-session.target" ];
|
||||
after = [ "graphical-session.target" ];
|
||||
|
||||
serviceConfig.Type = "oneshot";
|
||||
serviceConfig.ExecStart = ''
|
||||
# Ensure destination exists
|
||||
mkdir -p ${wallpaperDst}
|
||||
|
||||
# Copy wallpapers: overwrite newer files, do not delete existing files
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user