1
0
Fork 0
nixos-config/home/desktop/wallpaper.nix

37 lines
1.2 KiB
Nix
Raw Normal View History

2019-11-29 16:52:50 +00:00
{ lib, pkgs, config, ... }:
let
inherit (import ../../lib) writeHaskellScript;
randomWallpaper = writeHaskellScript {
name = "random-wallpaper";
2020-01-19 16:40:02 +00:00
imports = [ "System.Random" ];
2019-11-29 16:52:50 +00:00
bins = [ pkgs.coreutils pkgs.sway ];
} ''
2020-05-09 15:01:10 +00:00
linkPath = "/home/maralorn/volatile/wallpaper.jpg"
2020-01-19 17:42:41 +00:00
main = do
2020-05-05 23:40:57 +00:00
mode <- cat "/home/maralorn/tmp/mode" |> captureTrim
(lines . decodeUtf8 -> files) <- ls ([i|/home/maralorn/.wallpapers/#{mode}|] :: String) |> captureTrim
2020-01-19 17:42:41 +00:00
((files Unsafe.!!) -> file) <- getStdRandom $ randomR (0, length files - 1)
2020-05-09 15:01:10 +00:00
(decodeUtf8 -> current) <- readlink linkPath |> captureTrim
let new = [i|/home/maralorn/.wallpapers/#{mode}/#{file}|] :: String
when (new /= current) $ do
2020-05-09 15:45:47 +00:00
ln "-sf" new linkPath
2020-05-09 15:01:10 +00:00
swaymsg "output * bg /home/maralorn/volatile/wallpaper.jpg fill"
2019-11-29 16:52:50 +00:00
'';
in {
2020-05-05 23:40:57 +00:00
home.packages = [ randomWallpaper ];
2019-11-29 16:52:50 +00:00
systemd.user = {
services.random-wallpaper = {
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 = {
2020-05-09 15:45:47 +00:00
Timer = { OnCalendar = "*:00/30:00"; };
2020-01-19 16:40:02 +00:00
Install = { WantedBy = [ "timers.target" ]; };
2019-11-29 16:52:50 +00:00
};
};
}