stockholm/krebs/3modules/fetchWallpaper.nix

96 lines
2.2 KiB
Nix
Raw Normal View History

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
cfg = config.krebs.fetchWallpaper;
2015-12-12 16:50:33 +00:00
out = {
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;
default = "/var/lib/wallpaper";
2015-12-12 16:50:33 +00:00
};
display = mkOption {
type = types.str;
default = ":${toString config.services.xserver.display}";
2015-12-12 16:50:33 +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" ''
set -euf
mkdir -p ${cfg.stateDir}
chmod o+rx ${cfg.stateDir}
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 = {
users.users.fetchWallpaper = {
name = "fetchWallpaper";
2018-12-03 08:46:09 +00:00
uid = genid_uint31 "fetchWallpaper";
description = "fetchWallpaper user";
2021-10-23 10:08:58 +00:00
group = "fetchWallpaper";
home = cfg.stateDir;
createHome = true;
2021-06-03 18:15:42 +00:00
isSystemUser = true;
};
2021-10-23 10:08:58 +00:00
users.groups.fetchWallpaper = {};
systemd.timers.fetchWallpaper = {
2015-12-12 16:50:33 +00:00
description = "fetch wallpaper timer";
wantedBy = [ "timers.target" ];
timerConfig = cfg.timerConfig;
};
systemd.services.fetchWallpaper = {
2015-12-12 16:50:33 +00:00
description = "fetch wallpaper";
after = [ "network.target" ];
2015-12-12 16:50:33 +00:00
path = with pkgs; [
curl
feh
];
environment = {
URL = cfg.url;
DISPLAY = cfg.display;
2015-12-12 16:50:33 +00:00
};
restartIfChanged = true;
serviceConfig = {
Type = "simple";
ExecStart = fetchWallpaperScript;
User = "fetchWallpaper";
2015-12-12 16:50:33 +00:00
};
unitConfig = cfg.unitConfig;
2015-12-12 16:50:33 +00:00
};
};
in out