-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhome-manager-service.nix
140 lines (121 loc) · 3.89 KB
/
home-manager-service.nix
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
{ config, lib, pkgs, ... }:
with lib;
let
prog = pkgs.callPackage ./default.nix { };
cfg = config.services.feh-random-background;
flags = lib.concatStringsSep " " (
[
"--bg-${cfg.display}"
]
++ lib.optional (!cfg.enableXinerama) "--no-xinerama"
);
in
{
meta.maintainers = [ maintainers.kovirobi ];
options = {
services.feh-random-background = {
enable = mkEnableOption "random desktop background";
prog = mkOption {
type = types.str;
default = "${prog}/bin/feh-random-background";
example = "\${pkgs.feh}/bin/feh";
description = ''
The program to call to set the random background. Uses the
environment variable BGDIR for the imageDirectory option.
'';
};
imageDirectory = mkOption {
type = types.str;
default = "${config.home.homeDirectory}/backgrounds";
example = "\${config.home.homeDirectory}/backgrounds";
description = ''
The directory of images from which a background should be
chosen. Should be formatted in a way understood by systemd.
Default to example.
'';
};
stateFile = mkOption {
type = types.str;
default = "${config.home.homeDirectory}/.feh-random-background-list";
example = "\${config.home.homeDirectory}/.feh-random-background-list";
description = ''
The state file of the not-yet-seen random backgrounds. Should be
formatted in a way understood by systemd.
Default to example.
'';
};
extensionRegEx = mkOption {
type = types.str;
default = "png\\|jpg\\|jpeg\\|gif\\|tiff";
example = "png\\|jpg\\|jpeg\\|gif\\|tiff";
description = ''
Regular expression matching the extensions of the files
to be used as wallpapers.
Default to example.
'';
};
display = mkOption {
type = types.enum [ "center" "fill" "max" "scale" "tile" ];
default = "fill";
description = "Display background images according to this option.";
};
interval = mkOption {
default = null;
type = types.nullOr types.str;
example = "1h";
description = ''
The duration between changing background image, set to null
to only set background when logging in. Should be formatted
as a duration understood by systemd.
'';
};
enableXinerama = mkOption {
default = true;
type = types.bool;
description = ''
Will place a separate image per screen when enabled,
otherwise a single image will be stretched across all
screens.
'';
};
};
};
config = mkIf cfg.enable (
mkMerge ([
{
systemd.user.services.feh-random-background = {
Unit = {
Description = "Set random desktop background using feh";
After = [ "graphical-session-pre.target" ];
PartOf = [ "graphical-session.target" ];
};
Service = {
Type = "oneshot";
Environment = [
"BGDIR=${escapeShellArg cfg.imageDirectory}"
"BGSTATE=${escapeShellArg cfg.stateFile}"
"BGEXTENSIONRE=${escapeShellArg (escape [ "\\" ] cfg.extensionRegEx)}"
];
ExecStart = "${cfg.prog} ${flags}";
IOSchedulingClass = "idle";
};
Install = {
WantedBy = [ "graphical-session.target" ];
};
};
}
(mkIf (cfg.interval != null) {
systemd.user.timers.feh-random-background = {
Unit = {
Description = "Set random desktop background using feh";
};
Timer = {
OnUnitActiveSec = cfg.interval;
};
Install = {
WantedBy = [ "timers.target" ];
};
};
})
]));
}