summaryrefslogtreecommitdiffstats
path: root/lass/3modules/realwallpaper.nix
blob: 85dd35233ae0f25c09d600bb3b43eb37ca072a49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
arg@{ config, lib, pkgs, ... }:

let
  inherit (lib)
    mkEnableOption
    mkOption
    types
    mkIf
  ;

  lpkgs = import ../5pkgs { inherit pkgs; };

  cfg = config.lass.realwallpaper;

  out = {
    options.lass.realwallpaper = api;
    config = mkIf cfg.enable imp;
  };

  api = {
    enable = mkEnableOption "realwallpaper";

    workingDir = mkOption {
      type = types.str;
      default = "/var/realwallpaper/";
    };

    nightmap = mkOption {
      type = types.str;
      default = "http://eoimages.gsfc.nasa.gov/images/imagerecords/55000/55167/earth_lights_lrg.jpg";
    };

    daymap = mkOption {
      type = types.str;
      default = "http://www.nnvl.noaa.gov/images/globaldata/SnowIceCover_Daily.png";
    };

    cloudmap = mkOption {
      type = types.str;
      default = "http://xplanetclouds.com/free/local/clouds_2048.jpg";
    };

    outFile = mkOption {
      type = types.str;
      default = "/tmp/wallpaper.png";
    };

    timerConfig = mkOption {
      type = types.unspecified;
      default = {
        OnCalendar = "*:0/15";
      };
    };

  };

  imp = {
    systemd.timers.realwallpaper = {
      description = "real wallpaper generator timer";

      timerConfig = cfg.timerConfig;
    };

    systemd.services.realwallpaper = {
      description = "real wallpaper generator";
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];

      path = with pkgs; [
        xplanet
        imagemagick
        curl
        file
      ];

      environment = {
        working_dir = cfg.workingDir;
        nightmap_url = cfg.nightmap;
        daymap_url = cfg.daymap;
        cloudmap_url = cfg.cloudmap;
        out_file = cfg.outFile;
      };

      restartIfChanged = true;

      serviceConfig = {
        Type = "simple";
        ExecStart = "${lpkgs.realwallpaper}/realwallpaper.sh";
        User = "realwallpaper";
      };
    };

    users.extraUsers.realwallpaper = {
      uid = 2009435407; #genid realwallpaper
      home = cfg.workingDir;
      createHome = true;
    };
  };

in
out