diff options
author | lassulus <lass@aidsballs.de> | 2015-12-12 17:50:33 +0100 |
---|---|---|
committer | lassulus <lass@aidsballs.de> | 2015-12-12 17:50:33 +0100 |
commit | 5fde514b88336b3ed00d41ef2e72ad4e2da23deb (patch) | |
tree | 1427504d227e805112c934dc6b20362131ea2994 /lass/3modules | |
parent | ee4546c9a4de6886f370f7ef59f327ef5f2251b1 (diff) |
l 3: add fetchWallpaper.nix
Diffstat (limited to 'lass/3modules')
-rw-r--r-- | lass/3modules/default.nix | 1 | ||||
-rw-r--r-- | lass/3modules/fetchWallpaper.nix | 89 |
2 files changed, 90 insertions, 0 deletions
diff --git a/lass/3modules/default.nix b/lass/3modules/default.nix index 0dcad971c..5fa5160ee 100644 --- a/lass/3modules/default.nix +++ b/lass/3modules/default.nix @@ -8,5 +8,6 @@ _: ./urxvtd.nix ./xresources.nix ./wordpress_nginx.nix + ./fetchWallpaper.nix ]; } diff --git a/lass/3modules/fetchWallpaper.nix b/lass/3modules/fetchWallpaper.nix new file mode 100644 index 000000000..9baebedbd --- /dev/null +++ b/lass/3modules/fetchWallpaper.nix @@ -0,0 +1,89 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.lass.fetchWallpaper; + + out = { + options.lass.fetchWallpaper = api; + config = mkIf cfg.enable imp; + }; + + api = { + enable = mkEnableOption "fetch wallpaper"; + predicate = mkOption { + type = with types; nullOr path; + default = null; + }; + url = mkOption { + type = types.str; + }; + timerConfig = mkOption { + type = types.unspecified; + default = { + OnCalendar = "*:00,10,20,30,40,50"; + }; + }; + stateDir = mkOption { + type = types.str; + default = "/tmp/wallpaper"; + }; + display = mkOption { + type = types.str; + default = ":11"; + }; + }; + + fetchWallpaperScript = pkgs.writeScript "fetchWallpaper" '' + #! ${pkgs.bash}/bin/bash + ${if (cfg.predicate == null) then "" else '' + ${cfg.predicate} + if [ $? -ne 0 ]; then + echo "predicate failed" + exit 23 + fi + ''} + mkdir -p ${shell.escape cfg.stateDir} + curl -s -o ${shell.escape cfg.stateDir}/wallpaper -z ${shell.escape cfg.stateDir}/wallpaper ${shell.escape cfg.url} + feh --no-fehbg --bg-scale ${shell.escape cfg.stateDir}/wallpaper + ''; + + imp = { + users.extraUsers.fetchWallpaper = { + name = "fetchWallpaper"; + uid = 3332383611; #genid fetchWallpaper + description = "fetchWallpaper user"; + home = "/var/empty"; + }; + + 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"; + }; + }; + }; +in out |