This repository has no description
2.0 kB
79 lines
1{ config, lib, pkgs, ... }:
2
3let
4 cfg = config.lass.fetchWallpaper;
5
6 fetchWallpaperScript = pkgs.writers.writeDash "fetchWallpaper" ''
7 set -eufx
8
9 curl -v -s -o wallpaper.tmp -z wallpaper.tmp ${lib.escapeShellArg cfg.url} && cp wallpaper.tmp wallpaper
10 feh --no-fehbg --bg-scale wallpaper
11 '';
12
13in {
14 options.lass.fetchWallpaper = {
15 enable = lib.mkEnableOption "fetch wallpaper";
16 url = lib.mkOption {
17 type = lib.types.str;
18 };
19 timerConfig = lib.mkOption {
20 type = lib.types.unspecified;
21 default = {
22 OnCalendar = "*:00,10,20,30,40,50";
23 };
24 };
25 display = lib.mkOption {
26 type = lib.types.str;
27 default = ":${toString config.services.xserver.display}";
28 };
29 unitConfig = lib.mkOption {
30 type = lib.types.attrsOf lib.types.str;
31 description = "Extra unit configuration for fetchWallpaper to define conditions and assertions for the unit";
32 example = lib.literalExample ''
33 # do not start when running on umts
34 { ConditionPathExists = "!/var/run/ppp0.pid"; }
35 '';
36 default = {};
37 };
38 };
39
40 config = lib.mkIf cfg.enable {
41 systemd.timers.fetchWallpaper = {
42 description = "fetch wallpaper timer";
43 wantedBy = [ "timers.target" ];
44
45 timerConfig = cfg.timerConfig;
46 };
47 systemd.services.fetchWallpaper = {
48 description = "fetch wallpaper";
49 after = [ "network.target" ];
50
51 path = with pkgs; [
52 curl
53 feh
54 ];
55
56 environment = {
57 URL = cfg.url;
58 DISPLAY = cfg.display;
59 };
60 restartIfChanged = true;
61
62 serviceConfig = {
63 Type = "simple";
64 ExecStart = fetchWallpaperScript;
65 StateDirectory = "wallpaper";
66 StateDirectoryMode = "0755";
67 WorkingDirectory = "/var/lib/wallpaper";
68 };
69
70 unitConfig = cfg.unitConfig;
71 };
72
73 users.users.wallpaper = {
74 isSystemUser = true;
75 group = "wallpaper";
76 };
77 users.groups.wallpaper = {};
78 };
79}