fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
2.9 KiB102 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.services.random-background;
8
9  flags = lib.concatStringsSep " "
10    ([ "--bg-${cfg.display}" "--no-fehbg" "--randomize" ]
11      ++ lib.optional (!cfg.enableXinerama) "--no-xinerama");
12
13in {
14  meta.maintainers = [ maintainers.rycee ];
15
16  options = {
17    services.random-background = {
18      enable = mkEnableOption "" // {
19        description = ''
20          Whether to enable random desktop background.
21
22          Note, if you are using NixOS and have set up a custom
23          desktop manager session for Home Manager, then the session
24          configuration must have the `bgSupport`
25          option set to `true` or the background
26          image set by this module may be overwritten.
27        '';
28      };
29
30      imageDirectory = mkOption {
31        type = types.str;
32        example = "%h/backgrounds";
33        description = ''
34          The directory of images from which a background should be
35          chosen. Should be formatted in a way understood by systemd,
36          e.g., '%h' is the home directory.
37        '';
38      };
39
40      display = mkOption {
41        type = types.enum [ "center" "fill" "max" "scale" "tile" ];
42        default = "fill";
43        description = "Display background images according to this option.";
44      };
45
46      interval = mkOption {
47        default = null;
48        type = types.nullOr types.str;
49        example = "1h";
50        description = ''
51          The duration between changing background image, set to null
52          to only set background when logging in. Should be formatted
53          as a duration understood by systemd.
54        '';
55      };
56
57      enableXinerama = mkOption {
58        default = true;
59        type = types.bool;
60        description = ''
61          Will place a separate image per screen when enabled,
62          otherwise a single image will be stretched across all
63          screens.
64        '';
65      };
66    };
67  };
68
69  config = mkIf cfg.enable (mkMerge ([
70    {
71      assertions = [
72        (hm.assertions.assertPlatform "services.random-background" pkgs
73          platforms.linux)
74      ];
75
76      systemd.user.services.random-background = {
77        Unit = {
78          Description = "Set random desktop background using feh";
79          After = [ "graphical-session-pre.target" ];
80          PartOf = [ "graphical-session.target" ];
81        };
82
83        Service = {
84          Type = "oneshot";
85          ExecStart = "${pkgs.feh}/bin/feh ${flags} ${cfg.imageDirectory}";
86          IOSchedulingClass = "idle";
87        };
88
89        Install = { WantedBy = [ "graphical-session.target" ]; };
90      };
91    }
92    (mkIf (cfg.interval != null) {
93      systemd.user.timers.random-background = {
94        Unit = { Description = "Set random desktop background using feh"; };
95
96        Timer = { OnUnitActiveSec = cfg.interval; };
97
98        Install = { WantedBy = [ "timers.target" ]; };
99      };
100    })
101  ]));
102}