mirror of
https://github.com/nix-community/home-manager
synced 2025-01-11 11:39:49 +01:00
waybar: allow using attrs for settings (#2547)
Co-authored-by: Bruno Inec <binec@scaleway.com>
This commit is contained in:
parent
8b44e81978
commit
3db6036775
5 changed files with 105 additions and 43 deletions
|
@ -156,7 +156,7 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
settings = mkOption {
|
settings = mkOption {
|
||||||
type = listOf waybarBarConfig;
|
type = either (listOf waybarBarConfig) (attrsOf waybarBarConfig);
|
||||||
default = [ ];
|
default = [ ];
|
||||||
description = ''
|
description = ''
|
||||||
Configuration for Waybar, see <link
|
Configuration for Waybar, see <link
|
||||||
|
@ -164,8 +164,8 @@ in {
|
||||||
for supported values.
|
for supported values.
|
||||||
'';
|
'';
|
||||||
example = literalExpression ''
|
example = literalExpression ''
|
||||||
[
|
|
||||||
{
|
{
|
||||||
|
mainBar = {
|
||||||
layer = "top";
|
layer = "top";
|
||||||
position = "top";
|
position = "top";
|
||||||
height = 30;
|
height = 30;
|
||||||
|
@ -190,8 +190,8 @@ in {
|
||||||
''';
|
''';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
]
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -242,8 +242,15 @@ in {
|
||||||
settingsModules =
|
settingsModules =
|
||||||
optionalAttrs (configuration.modules != { }) configuration.modules;
|
optionalAttrs (configuration.modules != { }) configuration.modules;
|
||||||
in removeNulls (settingsWithoutModules // settingsModules);
|
in removeNulls (settingsWithoutModules // settingsModules);
|
||||||
|
|
||||||
|
# Allow using attrs for settings instead of a list in order to more easily override
|
||||||
|
settings = if builtins.isAttrs cfg.settings then
|
||||||
|
lib.attrValues cfg.settings
|
||||||
|
else
|
||||||
|
cfg.settings;
|
||||||
|
|
||||||
# The clean list of configurations
|
# The clean list of configurations
|
||||||
finalConfiguration = map makeConfiguration cfg.settings;
|
finalConfiguration = map makeConfiguration settings;
|
||||||
|
|
||||||
configSource = jsonFormat.generate "waybar-config.json" finalConfiguration;
|
configSource = jsonFormat.generate "waybar-config.json" finalConfiguration;
|
||||||
|
|
||||||
|
@ -255,7 +262,7 @@ in {
|
||||||
({
|
({
|
||||||
assertion =
|
assertion =
|
||||||
if lib.versionAtLeast config.home.stateVersion "22.05" then
|
if lib.versionAtLeast config.home.stateVersion "22.05" then
|
||||||
all (x: !hasAttr "modules" x) cfg.settings
|
all (x: !hasAttr "modules" x) settings
|
||||||
else
|
else
|
||||||
true;
|
true;
|
||||||
message = ''
|
message = ''
|
||||||
|
@ -267,7 +274,7 @@ in {
|
||||||
|
|
||||||
home.packages = [ cfg.package ];
|
home.packages = [ cfg.package ];
|
||||||
|
|
||||||
xdg.configFile."waybar/config" = mkIf (cfg.settings != [ ]) {
|
xdg.configFile."waybar/config" = mkIf (settings != [ ]) {
|
||||||
source = configSource;
|
source = configSource;
|
||||||
onChange = ''
|
onChange = ''
|
||||||
${pkgs.procps}/bin/pkill -u $USER -USR2 waybar || true
|
${pkgs.procps}/bin/pkill -u $USER -USR2 waybar || true
|
||||||
|
|
|
@ -3,5 +3,6 @@
|
||||||
./systemd-with-graphical-session-target.nix;
|
./systemd-with-graphical-session-target.nix;
|
||||||
waybar-styling = ./styling.nix;
|
waybar-styling = ./styling.nix;
|
||||||
waybar-settings-complex = ./settings-complex.nix;
|
waybar-settings-complex = ./settings-complex.nix;
|
||||||
|
waybar-settings-with-attrs = ./settings-with-attrs.nix;
|
||||||
waybar-deprecated-modules-option = ./deprecated-modules-option.nix;
|
waybar-deprecated-modules-option = ./deprecated-modules-option.nix;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,5 +43,21 @@
|
||||||
"all-outputs": true,
|
"all-outputs": true,
|
||||||
"disable-scroll": true
|
"disable-scroll": true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"modules-center": [
|
||||||
|
"clock"
|
||||||
|
],
|
||||||
|
"modules-left": [
|
||||||
|
"sway/mode"
|
||||||
|
],
|
||||||
|
"modules-right": [],
|
||||||
|
"output": [
|
||||||
|
"!DP-1"
|
||||||
|
],
|
||||||
|
"position": "bottom",
|
||||||
|
"sway/mode": {
|
||||||
|
"tooltip": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -9,7 +9,8 @@ with lib;
|
||||||
programs.waybar = {
|
programs.waybar = {
|
||||||
package = config.lib.test.mkStubPackage { outPath = "@waybar@"; };
|
package = config.lib.test.mkStubPackage { outPath = "@waybar@"; };
|
||||||
enable = true;
|
enable = true;
|
||||||
settings = [{
|
settings = [
|
||||||
|
{
|
||||||
layer = "top";
|
layer = "top";
|
||||||
position = "top";
|
position = "top";
|
||||||
height = 30;
|
height = 30;
|
||||||
|
@ -45,7 +46,15 @@ with lib;
|
||||||
in "${dummyScript}/bin/dummy";
|
in "${dummyScript}/bin/dummy";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}];
|
}
|
||||||
|
{
|
||||||
|
position = "bottom";
|
||||||
|
output = [ "!DP-1" ];
|
||||||
|
modules-left = [ "sway/mode" ];
|
||||||
|
modules-center = [ "clock" ];
|
||||||
|
modules = { "sway/mode" = { tooltip = true; }; };
|
||||||
|
}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
nmt.script = ''
|
nmt.script = ''
|
||||||
|
|
29
tests/modules/programs/waybar/settings-with-attrs.nix
Normal file
29
tests/modules/programs/waybar/settings-with-attrs.nix
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
home.stateVersion = "21.11";
|
||||||
|
|
||||||
|
programs.waybar = {
|
||||||
|
package = config.lib.test.mkStubPackage { outPath = "@waybar@"; };
|
||||||
|
enable = true;
|
||||||
|
settings = let
|
||||||
|
settingsComplex = (import ./settings-complex.nix {
|
||||||
|
inherit config lib pkgs;
|
||||||
|
}).config.programs.waybar.settings;
|
||||||
|
in {
|
||||||
|
mainBar = builtins.head settingsComplex;
|
||||||
|
secondaryBar = builtins.elemAt settingsComplex 1;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertPathNotExists home-files/.config/waybar/style.css
|
||||||
|
assertFileContent \
|
||||||
|
home-files/.config/waybar/config \
|
||||||
|
${./settings-complex-expected.json}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue