Skip to content

Commit acfd3c0

Browse files
authored
Merge branch 'snugnug:main' into main
2 parents 5839dca + baf1e9a commit acfd3c0

32 files changed

+353
-192
lines changed

docs/CONTRIBUTING.md

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,17 @@ avoid this:
247247
```nix
248248
config = mkIf cfg.enable {
249249
packages = [cfg.package];
250-
files.".config/alacritty/alacritty.toml".source = mkIf (cfg.settings != {}) (
251-
toml.generate "alacritty.toml" cfg.settings
252-
);
250+
files.".config/alacritty/alacritty.toml" = mkIf (cfg.settings != {}) {source = toml.generate "alacritty.toml" cfg.settings;};
253251
};
254252
```
255253

256254
Here all that is needed is a simple `mkIf` with a condition of the `settings`
257-
option not being left empty. In a case where you write to multiple files, you
258-
can use `optionalAttrs`, like so:
255+
option not being left empty. We put options like `source` and `text` inside the
256+
`mkIf` block so that the file will not appear in the evaluation results if
257+
`settings` is empty.
258+
259+
In a case where you write to multiple files, you can use `optionalAttrs`, like
260+
so:
259261

260262
```nix
261263
files = (
@@ -282,7 +284,7 @@ One last case is in the Hyprland module, where several checks and several
282284
options are needed to compile into one file. Here is how it is done:
283285

284286
```nix
285-
files = let
287+
xdg.config.files = let
286288
check = {
287289
plugins = cfg.plugins != [];
288290
settings = cfg.settings != {};
@@ -293,34 +295,33 @@ files = let
293295
extraConfig = cfg.extraConfig != "";
294296
};
295297
in {
296-
".config/hypr/hyprland.conf".text = mkIf (check.plugins || check.settings || check.variables.noUWSM || check.extraConfig) (
297-
optionalString check.plugins (pluginsToHyprconf cfg.plugins cfg.importantPrefixes)
298-
+ optionalString check.settings (toHyprconf {
299-
attrs = cfg.settings;
300-
inherit (cfg) importantPrefixes;
301-
})
302-
+ optionalString check.variables.noUWSM (toHyprconf {
303-
attrs.env =
304-
# https://wiki.hyprland.org/Configuring/Environment-variables/#xdg-specifications
305-
[
306-
"XDG_CURRENT_DESKTOP,Hyprland"
307-
"XDG_SESSION_TYPE,wayland"
308-
"XDG_SESSION_DESKTOP,Hyprland"
309-
]
310-
++ mapAttrsToList (key: value: "${key},${value}") config.environment.sessionVariables;
311-
})
312-
+ optionalString check.extraConfig cfg.extraConfig
313-
);
298+
"hypr/hyprland.conf" = mkIf (check.plugins || check.settings || check.variables.noUWSM || check.extraConfig) {
299+
text =
300+
optionalString check.plugins (pluginsToHyprconf cfg.plugins cfg.importantPrefixes)
301+
+ optionalString check.settings (toHyprconf {
302+
attrs = cfg.settings;
303+
inherit (cfg) importantPrefixes;
304+
})
305+
+ optionalString check.variables.noUWSM (toHyprconf {
306+
attrs.env =
307+
# https://wiki.hyprland.org/Configuring/Environment-variables/#xdg-specifications
308+
[
309+
"XDG_CURRENT_DESKTOP,Hyprland"
310+
"XDG_SESSION_TYPE,wayland"
311+
"XDG_SESSION_DESKTOP,Hyprland"
312+
]
313+
++ mapAttrsToList (key: value: "${key},${value}") config.environment.sessionVariables;
314+
})
315+
+ optionalString check.extraConfig cfg.extraConfig;
316+
};
314317
315318
/*
316319
uwsm environment variables are advised to be separated
317320
(see https://wiki.hyprland.org/Configuring/Environment-variables/)
318321
*/
319-
".config/uwsm/env".text =
320-
mkIf check.variables.withUWSM
321-
(toEnvExport config.environment.sessionVariables);
322+
"uwsm/env" = mkIf check.variables.withUWSM {text = toEnvExport config.environment.sessionVariables;};
322323
323-
".config/uwsm/env-hyprland".text = let
324+
"uwsm/env-hyprland" = let
324325
/*
325326
this is needed as we're using a predicate so we don't create an empty file
326327
(improvements are welcome)
@@ -329,7 +330,7 @@ in {
329330
filterKeysPrefixes ["HYPRLAND_" "AQ_"] config.environment.sessionVariables;
330331
in
331332
mkIf (check.variables.withUWSM && filteredVars != {})
332-
(toEnvExport filteredVars);
333+
{text = toEnvExport filteredVars;};
333334
};
334335
```
335336

modules/collection/desktops/hyprland.nix

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,34 +80,33 @@ in {
8080
extraConfig = cfg.extraConfig != "";
8181
};
8282
in {
83-
"hypr/hyprland.conf".text = mkIf (check.plugins || check.settings || check.variables.noUWSM || check.extraConfig) (
84-
optionalString check.plugins (pluginsToHyprconf cfg.plugins cfg.importantPrefixes)
85-
+ optionalString check.settings (toHyprconf {
86-
attrs = cfg.settings;
87-
inherit (cfg) importantPrefixes;
88-
})
89-
+ optionalString check.variables.noUWSM (toHyprconf {
90-
attrs.env =
91-
# https://wiki.hyprland.org/Configuring/Environment-variables/#xdg-specifications
92-
[
93-
"XDG_CURRENT_DESKTOP,Hyprland"
94-
"XDG_SESSION_TYPE,wayland"
95-
"XDG_SESSION_DESKTOP,Hyprland"
96-
]
97-
++ mapAttrsToList (key: value: "${key},${value}") config.environment.sessionVariables;
98-
})
99-
+ optionalString check.extraConfig cfg.extraConfig
100-
);
83+
"hypr/hyprland.conf" = mkIf (check.plugins || check.settings || check.variables.noUWSM || check.extraConfig) {
84+
text =
85+
optionalString check.plugins (pluginsToHyprconf cfg.plugins cfg.importantPrefixes)
86+
+ optionalString check.settings (toHyprconf {
87+
attrs = cfg.settings;
88+
inherit (cfg) importantPrefixes;
89+
})
90+
+ optionalString check.variables.noUWSM (toHyprconf {
91+
attrs.env =
92+
# https://wiki.hyprland.org/Configuring/Environment-variables/#xdg-specifications
93+
[
94+
"XDG_CURRENT_DESKTOP,Hyprland"
95+
"XDG_SESSION_TYPE,wayland"
96+
"XDG_SESSION_DESKTOP,Hyprland"
97+
]
98+
++ mapAttrsToList (key: value: "${key},${value}") config.environment.sessionVariables;
99+
})
100+
+ optionalString check.extraConfig cfg.extraConfig;
101+
};
101102

102103
/*
103104
uwsm environment variables are advised to be separated
104105
(see https://wiki.hyprland.org/Configuring/Environment-variables/)
105106
*/
106-
"uwsm/env".text =
107-
mkIf check.variables.withUWSM
108-
(toEnvExport config.environment.sessionVariables);
107+
"uwsm/env" = mkIf check.variables.withUWSM {text = toEnvExport config.environment.sessionVariables;};
109108

110-
"uwsm/env-hyprland".text = let
109+
"uwsm/env-hyprland" = let
111110
/*
112111
this is needed as we're using a predicate so we don't create an empty file
113112
(improvements are welcome)
@@ -116,7 +115,7 @@ in {
116115
filterKeysPrefixes ["HYPRLAND_" "AQ_"] config.environment.sessionVariables;
117116
in
118117
mkIf (check.variables.withUWSM && filteredVars != {})
119-
(toEnvExport filteredVars);
118+
{text = toEnvExport filteredVars;};
120119
};
121120
};
122121
}

modules/collection/misc/gtk.nix

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ in {
5858
[official GTK documentation]: https://docs.gtk.org/gtk3/class.Settings.html
5959
'';
6060
};
61+
gtk2Location = mkOption {
62+
type = str;
63+
default = ".gtkrc-2.0";
64+
defaultText = "$HOME/.gtkrc-2.0";
65+
example = ".config/gtk-2.0/gtkrc";
66+
description = ''
67+
The location relative to {env}`$HOME` to write the GTK-2.0 settings to.
68+
By default, apps search at {file}`$HOME/.gtkrc-2.0`, but the environmental
69+
variable {env}`GTK2_RC_FILES` can be set to a different location.
70+
'';
71+
};
6172
css = {
6273
gtk3 = mkOption {
6374
type = lines;
@@ -106,12 +117,12 @@ in {
106117
inherit (cfg) packages;
107118

108119
files = optionalAttrs (cfg.settings != {}) {
109-
".gtkrc-2.0".text = toGtk2Text {inherit (cfg) settings;};
120+
${cfg.gtk2Location}.text = toGtk2Text {inherit (cfg) settings;};
110121
};
111122
xdg.config.files = (
112123
optionalAttrs (cfg.settings != {}) {
113-
"gtk-3.0/settings.ini".text = toGtkINI {Settings = cfg.settings;};
114-
"gtk-4.0/settings.ini".text = toGtkINI {Settings = cfg.settings;};
124+
".config/gtk-3.0/settings.ini".text = toGtkINI {Settings = cfg.settings;};
125+
".config/gtk-4.0/settings.ini".text = toGtkINI {Settings = cfg.settings;};
115126
}
116127
// optionalAttrs (cfg.css.gtk3 != "") {
117128
"gtk-3.0/gtk.css".text = cfg.css.gtk3;
@@ -126,7 +137,7 @@ in {
126137

127138
# Set sessionVariables to load
128139
environment.sessionVariables = {
129-
GTK2_RC_FILES = "${config.directory}/.gtkrc-2.0";
140+
GTK2_RC_FILES = "${config.directory}/${cfg.gtk2Location}";
130141
GTK_THEME = mkIf (hasAttr "theme-name" cfg.settings) cfg.settings.theme-name;
131142
};
132143
};

modules/collection/programs/alacritty.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ in {
4545

4646
config = mkIf cfg.enable {
4747
packages = mkIf (cfg.package != null) [cfg.package];
48-
xdg.config.files."alacritty/alacritty.toml".source = mkIf (cfg.settings != {}) (
49-
toml.generate "alacritty.toml" cfg.settings
50-
);
48+
xdg.config.files."alacritty/alacritty.toml" = mkIf (cfg.settings != {}) {
49+
source = toml.generate "alacritty.toml" cfg.settings;
50+
};
5151
};
5252
}

modules/collection/programs/beets.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ in {
6969

7070
config = mkIf cfg.enable {
7171
packages = mkIf (cfg.package != null) [cfg.package];
72-
xdg.config.files."beets/config.yaml".source = mkIf (cfg.settings != {}) (
73-
yaml.generate "config.yaml" cfg.settings
74-
);
72+
xdg.config.files."beets/config.yaml" = mkIf (cfg.settings != {}) {
73+
source = yaml.generate "config.yaml" cfg.settings;
74+
};
7575
};
7676
}

modules/collection/programs/bottom.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ in {
4040

4141
config = mkIf cfg.enable {
4242
packages = mkIf (cfg.package != null) [cfg.package];
43-
xdg.config.files."bottom/bottom.toml".source = mkIf (cfg.settings != {}) (
44-
toml.generate "bottom.toml" cfg.settings
45-
);
43+
xdg.config.files."bottom/bottom.toml" = mkIf (cfg.settings != {}) {
44+
source = toml.generate "bottom.toml" cfg.settings;
45+
};
4646
};
4747
}

modules/collection/programs/direnv.nix

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ in {
7373
config = mkIf cfg.enable {
7474
packages = mkIf (cfg.package != null) [cfg.package];
7575
xdg.config.files = {
76-
"direnv/direnv.toml".source = mkIf (cfg.settings != {}) (
77-
toml.generate "direnv-config.toml" cfg.settings
78-
);
79-
"direnv/direnvrc".text = mkIf (cfg.direnvrc != "") cfg.direnvrc;
80-
"direnv/lib/nix-direnv.sh".source = mkIf cfg.integrations.nix-direnv.enable "${cfg.integrations.nix-direnv.package}/share/nix-direnv/direnvrc";
76+
"direnv/direnv.toml" = mkIf (cfg.settings != {}) {
77+
source = toml.generate "direnv-config.toml" cfg.settings;
78+
};
79+
"direnv/direnvrc" = mkIf (cfg.direnvrc != "") {text = cfg.direnvrc;};
80+
"direnv/lib/nix-direnv.sh" = mkIf cfg.integrations.nix-direnv.enable {source = "${cfg.integrations.nix-direnv.package}/share/nix-direnv/direnvrc";};
8181
};
8282

8383
rum.programs.fish.config = mkIf cfg.integrations.fish.enable (

modules/collection/programs/fish.nix

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,22 @@ in {
187187

188188
xdg.config.files =
189189
{
190-
"fish/config.fish".source = mkIf (cfg.config != "") (writeFish "config.fish" cfg.config);
191-
"fish/conf.d/rum-environment-variables.fish".text = mkIf (env != {}) ''
192-
${concatMapAttrsStringSep "\n" (name: value: "set --global --export ${name} ${toString value}") env}
193-
'';
194-
"fish/conf.d/rum-abbreviations.fish".text = mkIf (cfg.abbrs != {}) ''
195-
${concatMapAttrsStringSep "\n" (name: value: "abbr --add -- ${name} ${escapeShellArg (toString value)}") cfg.abbrs}
196-
'';
197-
"fish/conf.d/rum-aliases.fish".text = mkIf (cfg.aliases != {}) ''
198-
${concatMapAttrsStringSep "\n" (name: value: "alias -- ${name} ${escapeShellArg (toString value)}") cfg.aliases}
199-
'';
190+
"fish/config.fish" = mkIf (cfg.config != "") {source = writeFish "config.fish" cfg.config;};
191+
"fish/conf.d/rum-environment-variables.fish" = mkIf (env != {}) {
192+
text = ''
193+
${concatMapAttrsStringSep "\n" (name: value: "set --global --export ${name} ${toString value}") env}
194+
'';
195+
};
196+
"fish/conf.d/rum-abbreviations.fish" = mkIf (cfg.abbrs != {}) {
197+
text = ''
198+
${concatMapAttrsStringSep "\n" (name: value: "abbr --add -- ${name} ${escapeShellArg (toString value)}") cfg.abbrs}
199+
'';
200+
};
201+
"fish/conf.d/rum-aliases.fish" = mkIf (cfg.aliases != {}) {
202+
text = ''
203+
${concatMapAttrsStringSep "\n" (name: value: "alias -- ${name} ${escapeShellArg (toString value)}") cfg.aliases}
204+
'';
205+
};
200206
}
201207
// (mapAttrs' (name: val: nameValuePair "fish/functions/${name}.fish" {source = toFishFunc val name;}) cfg.functions)
202208
// (mapAttrs' (name: val: nameValuePair "fish/conf.d/${name}.fish" {source = writeFish "${name}.fish" val;}) cfg.earlyConfigFiles);

modules/collection/programs/flameshot.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ in {
3838

3939
config = mkIf cfg.enable {
4040
packages = mkIf (cfg.package != null) [cfg.package];
41-
xdg.config.files."flameshot/flameshot.ini".source = mkIf (cfg.settings != {}) (
42-
ini.generate "flameshot.ini" cfg.settings
43-
);
41+
xdg.config.files."flameshot/flameshot.ini" = mkIf (cfg.settings != {}) {
42+
source = ini.generate "flameshot.ini" cfg.settings;
43+
};
4444
};
4545
}

modules/collection/programs/foot.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ in {
5252

5353
config = mkIf cfg.enable {
5454
packages = mkIf (cfg.package != null) [cfg.package];
55-
xdg.config.files."foot/foot.ini".source = mkIf (cfg.settings != {}) (
56-
ini.generate "foot.ini" cfg.settings
57-
);
55+
xdg.config.files."foot/foot.ini" = mkIf (cfg.settings != {}) {
56+
source = ini.generate "foot.ini" cfg.settings;
57+
};
5858
};
5959
}

0 commit comments

Comments
 (0)