2015-12-12 16:50:33 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
2016-10-20 18:54:38 +00:00
|
|
|
with import <stockholm/lib>;
|
2015-12-12 16:50:33 +00:00
|
|
|
|
|
|
|
let
|
2015-12-12 18:37:13 +00:00
|
|
|
cfg = config.krebs.fetchWallpaper;
|
2015-12-12 16:50:33 +00:00
|
|
|
|
|
|
|
out = {
|
2015-12-12 18:37:13 +00:00
|
|
|
options.krebs.fetchWallpaper = api;
|
2016-02-14 15:43:44 +00:00
|
|
|
config = lib.mkIf cfg.enable imp;
|
2015-12-12 16:50:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
api = {
|
|
|
|
enable = mkEnableOption "fetch wallpaper";
|
|
|
|
url = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
timerConfig = mkOption {
|
|
|
|
type = types.unspecified;
|
|
|
|
default = {
|
|
|
|
OnCalendar = "*:00,10,20,30,40,50";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
stateDir = mkOption {
|
|
|
|
type = types.str;
|
2017-03-14 10:17:10 +00:00
|
|
|
default = "/var/lib/wallpaper";
|
2015-12-12 16:50:33 +00:00
|
|
|
};
|
|
|
|
display = mkOption {
|
2017-12-03 21:29:18 +00:00
|
|
|
type = types.int;
|
|
|
|
default = config.services.xserver.display;
|
2015-12-12 16:50:33 +00:00
|
|
|
};
|
2016-02-11 10:04:19 +00:00
|
|
|
unitConfig = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
description = "Extra unit configuration for fetchWallpaper to define conditions and assertions for the unit";
|
|
|
|
example = literalExample ''
|
|
|
|
# do not start when running on umts
|
|
|
|
{ ConditionPathExists = "!/var/run/ppp0.pid"; }
|
|
|
|
'';
|
|
|
|
default = {};
|
|
|
|
};
|
2017-01-26 22:59:26 +00:00
|
|
|
maxTime = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
|
|
|
description = "Time to wait before download is aborted";
|
|
|
|
};
|
2015-12-12 16:50:33 +00:00
|
|
|
};
|
|
|
|
|
2016-04-26 23:31:26 +00:00
|
|
|
fetchWallpaperScript = pkgs.writeDash "fetchWallpaper" ''
|
2016-05-02 15:36:16 +00:00
|
|
|
set -euf
|
2016-02-11 10:04:19 +00:00
|
|
|
|
2017-02-16 18:40:04 +00:00
|
|
|
mkdir -p ${cfg.stateDir}
|
2017-07-22 21:01:39 +00:00
|
|
|
chmod o+rx ${cfg.stateDir}
|
2017-02-16 18:40:04 +00:00
|
|
|
cd ${cfg.stateDir}
|
2017-07-28 16:41:46 +00:00
|
|
|
(curl --max-time ${toString cfg.maxTime} -s -o wallpaper.tmp -z wallpaper.tmp ${shell.escape cfg.url} && cp wallpaper.tmp wallpaper) || :
|
2017-03-14 10:17:10 +00:00
|
|
|
feh --no-fehbg --bg-scale ${shell.escape cfg.stateDir}/wallpaper
|
2015-12-12 16:50:33 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
imp = {
|
2017-03-14 10:17:10 +00:00
|
|
|
users.users.fetchWallpaper = {
|
|
|
|
name = "fetchWallpaper";
|
|
|
|
uid = genid "fetchWallpaper";
|
|
|
|
description = "fetchWallpaper user";
|
|
|
|
home = cfg.stateDir;
|
|
|
|
createHome = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.timers.fetchWallpaper = {
|
2015-12-12 16:50:33 +00:00
|
|
|
description = "fetch wallpaper timer";
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
|
|
|
|
timerConfig = cfg.timerConfig;
|
|
|
|
};
|
2017-03-14 10:17:10 +00:00
|
|
|
systemd.services.fetchWallpaper = {
|
2015-12-12 16:50:33 +00:00
|
|
|
description = "fetch wallpaper";
|
2017-03-14 10:17:10 +00:00
|
|
|
after = [ "network.target" ];
|
2015-12-12 16:50:33 +00:00
|
|
|
|
|
|
|
path = with pkgs; [
|
|
|
|
curl
|
|
|
|
feh
|
|
|
|
];
|
|
|
|
|
|
|
|
environment = {
|
2017-03-14 10:17:10 +00:00
|
|
|
URL = cfg.url;
|
2017-12-03 21:29:18 +00:00
|
|
|
DISPLAY = ":${toString cfg.display}";
|
2015-12-12 16:50:33 +00:00
|
|
|
};
|
|
|
|
restartIfChanged = true;
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
ExecStart = fetchWallpaperScript;
|
2017-03-14 10:17:10 +00:00
|
|
|
User = "fetchWallpaper";
|
2015-12-12 16:50:33 +00:00
|
|
|
};
|
2016-02-11 10:04:19 +00:00
|
|
|
|
|
|
|
unitConfig = cfg.unitConfig;
|
2015-12-12 16:50:33 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in out
|