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

31 lines
1,002 B
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";
imports = [ "System.Random" "Control.Concurrent" ];
bins = [ pkgs.coreutils pkgs.sway ];
} ''
main = forever $ do
files <- fmap (lines . decodeUtf8) $ ls "/home/maralorn/.wallpapers" |> captureTrim
file <- fmap (files Prelude.!!) $ getStdRandom $ randomR (0, length files - 1)
cp ([i|/home/maralorn/.wallpapers/#{file}|] :: String) "/home/maralorn/volatile/wallpaper.jpg"
swaymsg "output * bg /home/maralorn/volatile/wallpaper.jpg fill"
threadDelay 300000000
'';
in {
systemd.user = {
services.random-wallpaper = {
Unit = { Description = "Random Wallpaper"; };
2019-12-09 15:40:58 +00:00
Service = {
ExecStart = "${randomWallpaper}/bin/random-wallpaper";
2019-12-15 12:52:03 +00:00
Restart = "always";
2019-12-09 15:40:58 +00:00
RestartSec = "10";
};
2019-11-29 16:52:50 +00:00
Install = { WantedBy = [ "graphical-session.target" ]; };
};
};
}