@@ -247,15 +247,17 @@ avoid this:
247247``` nix
248248config = 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
256254Here 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
261263files = (
@@ -282,7 +284,7 @@ One last case is in the Hyprland module, where several checks and several
282284options 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 };
295297in {
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)
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
0 commit comments