2015-12-12 16:50:33 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
2016-02-14 15:43:44 +00:00
|
|
|
with config.krebs.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;
|
2015-12-12 18:37:52 +00:00
|
|
|
default = "/var/lib/wallpaper";
|
2015-12-12 16:50:33 +00:00
|
|
|
};
|
|
|
|
display = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = ":11";
|
|
|
|
};
|
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
|
|
|
};
|
|
|
|
|
|
|
|
fetchWallpaperScript = pkgs.writeScript "fetchWallpaper" ''
|
|
|
|
#! ${pkgs.bash}/bin/bash
|
2016-05-02 15:36:16 +00:00
|
|
|
set -euf
|
2016-02-11 10:04:19 +00:00
|
|
|
|
2015-12-12 16:50:33 +00:00
|
|
|
mkdir -p ${shell.escape cfg.stateDir}
|
2016-05-02 15:36:16 +00:00
|
|
|
cd ${shell.escape cfg.stateDir}
|
|
|
|
curl -s -o wallpaper.tmp -z wallpaper ${shell.escape cfg.url} && mv wallpaper.tmp wallpaper
|
2015-12-12 16:50:33 +00:00
|
|
|
feh --no-fehbg --bg-scale ${shell.escape cfg.stateDir}/wallpaper
|
|
|
|
'';
|
|
|
|
|
|
|
|
imp = {
|
2015-12-12 18:37:52 +00:00
|
|
|
users.users.fetchWallpaper = {
|
2015-12-12 16:50:33 +00:00
|
|
|
name = "fetchWallpaper";
|
2015-12-26 04:55:13 +00:00
|
|
|
uid = genid "fetchWallpaper";
|
2015-12-12 16:50:33 +00:00
|
|
|
description = "fetchWallpaper user";
|
2015-12-12 18:37:52 +00:00
|
|
|
home = cfg.stateDir;
|
|
|
|
createHome = true;
|
2015-12-12 16:50:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.timers.fetchWallpaper = {
|
|
|
|
description = "fetch wallpaper timer";
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
|
|
|
|
timerConfig = cfg.timerConfig;
|
|
|
|
};
|
|
|
|
systemd.services.fetchWallpaper = {
|
|
|
|
description = "fetch wallpaper";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
|
|
|
|
path = with pkgs; [
|
|
|
|
curl
|
|
|
|
feh
|
|
|
|
];
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
URL = cfg.url;
|
|
|
|
DISPLAY = cfg.display;
|
|
|
|
};
|
|
|
|
restartIfChanged = true;
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
ExecStart = fetchWallpaperScript;
|
|
|
|
User = "fetchWallpaper";
|
|
|
|
};
|
2016-02-11 10:04:19 +00:00
|
|
|
|
|
|
|
unitConfig = cfg.unitConfig;
|
2015-12-12 16:50:33 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in out
|