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 22:31:31 +00:00
|
|
|
type = types.str;
|
|
|
|
default = ":${toString 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 = {};
|
|
|
|
};
|
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}
|
2018-11-26 23:58:57 +00:00
|
|
|
(curl -s -o wallpaper.tmp -z wallpaper.tmp ${shell.escape cfg.url} && cp wallpaper.tmp wallpaper) || :
|
|
|
|
feh --no-fehbg --bg-scale wallpaper
|
2015-12-12 16:50:33 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
imp = {
|
2017-03-14 10:17:10 +00:00
|
|
|
users.users.fetchWallpaper = {
|
|
|
|
name = "fetchWallpaper";
|
2018-12-03 08:46:09 +00:00
|
|
|
uid = genid_uint31 "fetchWallpaper";
|
2017-03-14 10:17:10 +00:00
|
|
|
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 22:31:31 +00:00
|
|
|
DISPLAY = 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
|