1
0
Fork 0
nixos-config/home-manager/roles/wallpaper.nix

43 lines
1.3 KiB
Nix
Raw Normal View History

2022-03-08 01:42:46 +00:00
{
pkgs,
config,
...
}: let
2021-08-03 21:46:29 +00:00
modeFile = "${config.home.homeDirectory}/.mode";
2021-07-06 11:04:16 +00:00
wallPapers = "${config.home.homeDirectory}/media/images/wallpapers";
2021-05-18 14:33:28 +00:00
randomWallpaper = pkgs.writeHaskellScript
2022-03-08 01:42:46 +00:00
{
name = "random-wallpaper";
imports = ["System.Random"];
bins = [pkgs.coreutils pkgs.glib];
} ''
2020-01-19 17:42:41 +00:00
main = do
2021-07-05 15:45:47 +00:00
mode <- cat "${modeFile}" |> captureTrim
2021-07-06 11:04:16 +00:00
(lines . decodeUtf8 -> files) <- ls ([i|${wallPapers}/#{mode}|] :: String) |> captureTrim
2020-01-19 17:42:41 +00:00
((files Unsafe.!!) -> file) <- getStdRandom $ randomR (0, length files - 1)
2020-05-16 11:19:05 +00:00
(decodeUtf8 -> current) <- gsettings "get" "org.gnome.desktop.background" "picture-uri" |> captureTrim
2021-07-06 11:04:16 +00:00
let new = [i|file:///${wallPapers}/#{mode}/#{file}|] :: String
2020-05-20 07:35:05 +00:00
when (new /= current) $ do
2020-05-16 11:19:05 +00:00
gsettings "set" "org.gnome.desktop.background" "picture-uri" new
2020-05-19 22:19:41 +00:00
gsettings "set" "org.gnome.desktop.screensaver" "picture-uri" new
2019-11-29 16:52:50 +00:00
'';
2022-03-08 01:42:46 +00:00
in {
home.packages = [randomWallpaper];
2019-11-29 16:52:50 +00:00
systemd.user = {
services.random-wallpaper = {
2022-03-08 01:42:46 +00:00
Unit = {Description = "Random Wallpaper";};
2019-12-09 15:40:58 +00:00
Service = {
ExecStart = "${randomWallpaper}/bin/random-wallpaper";
2020-01-19 16:40:02 +00:00
Type = "oneshot";
2019-12-09 15:40:58 +00:00
};
2020-01-19 16:40:02 +00:00
};
timers.random-wallpaper = {
2022-03-08 01:42:46 +00:00
Timer = {
OnCalendar = "*:00/30:00";
OnActiveSec = 1;
};
Install = {WantedBy = ["timers.target"];};
2019-11-29 16:52:50 +00:00
};
};
}