Specify waybar config in nix.
This is to facilitate having different waybar configs for each machine.
This commit is contained in:
@@ -6,6 +6,11 @@
|
||||
}:
|
||||
|
||||
let
|
||||
settings_format = pkgs.formats.json { };
|
||||
waybar_config_json = settings_format.generate "config" config.me.waybar.config;
|
||||
launch_waybar = pkgs.writeShellScript "launch_waybar" ''
|
||||
exec waybar --config '${waybar_config_json}' --style '${./files/style.css}'
|
||||
'';
|
||||
waybar_sway_config = pkgs.writeTextFile {
|
||||
name = "waybar.conf";
|
||||
text = ''
|
||||
@@ -17,7 +22,7 @@ let
|
||||
position top
|
||||
|
||||
font pango:Cascadia Mono, FontAwesome 10
|
||||
swaybar_command waybar
|
||||
swaybar_command ${launch_waybar}
|
||||
|
||||
colors {
|
||||
statusline #ffffff
|
||||
@@ -28,54 +33,39 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
waybar_available_memory =
|
||||
(pkgs.writeScriptBin "waybar_custom_available_memory" (
|
||||
patchScriptBin =
|
||||
filename: contents:
|
||||
((pkgs.writeScriptBin filename contents).overrideAttrs (old: {
|
||||
buildCommand = "${old.buildCommand}\n patchShebangs $out";
|
||||
}));
|
||||
waybar_available_memory = (
|
||||
patchScriptBin "waybar_custom_available_memory" (
|
||||
builtins.readFile ./files/waybar_scripts/waybar_available_memory_linux.bash
|
||||
)).overrideAttrs
|
||||
(old: {
|
||||
buildCommand = "${old.buildCommand}\n patchShebangs $out";
|
||||
|
||||
});
|
||||
waybar_battery =
|
||||
(pkgs.writeScriptBin "waybar_custom_battery" (
|
||||
)
|
||||
);
|
||||
waybar_battery = (
|
||||
patchScriptBin "waybar_custom_battery" (
|
||||
builtins.readFile ./files/waybar_scripts/waybar_battery_linux.bash
|
||||
)).overrideAttrs
|
||||
(old: {
|
||||
buildCommand = "${old.buildCommand}\n patchShebangs $out";
|
||||
|
||||
});
|
||||
waybar_clock =
|
||||
(pkgs.writeScriptBin "waybar_custom_clock" (
|
||||
)
|
||||
);
|
||||
waybar_clock = (
|
||||
patchScriptBin "waybar_custom_clock" (
|
||||
builtins.readFile ./files/waybar_scripts/waybar_custom_clock.py
|
||||
)).overrideAttrs
|
||||
(old: {
|
||||
buildCommand = "${old.buildCommand}\n patchShebangs $out";
|
||||
|
||||
});
|
||||
waybar_night_mode =
|
||||
(pkgs.writeScriptBin "waybar_night_mode" (
|
||||
builtins.readFile ./files/waybar_scripts/waybar_night_mode.bash
|
||||
)).overrideAttrs
|
||||
(old: {
|
||||
buildCommand = "${old.buildCommand}\n patchShebangs $out";
|
||||
|
||||
});
|
||||
waybar_sound =
|
||||
(pkgs.writeScriptBin "waybar_custom_sound" (
|
||||
)
|
||||
);
|
||||
waybar_night_mode = (
|
||||
patchScriptBin "waybar_night_mode" (builtins.readFile ./files/waybar_scripts/waybar_night_mode.bash)
|
||||
);
|
||||
waybar_sound = (
|
||||
patchScriptBin "waybar_custom_sound" (
|
||||
builtins.readFile ./files/waybar_scripts/waybar_sound_linux.bash
|
||||
)).overrideAttrs
|
||||
(old: {
|
||||
buildCommand = "${old.buildCommand}\n patchShebangs $out";
|
||||
|
||||
});
|
||||
waybar_temperature =
|
||||
(pkgs.writeScriptBin "waybar_custom_temperature" (
|
||||
)
|
||||
);
|
||||
waybar_temperature = (
|
||||
patchScriptBin "waybar_custom_temperature" (
|
||||
builtins.readFile ./files/waybar_scripts/waybar_temperature_linux.bash
|
||||
)).overrideAttrs
|
||||
(old: {
|
||||
buildCommand = "${old.buildCommand}\n patchShebangs $out";
|
||||
|
||||
});
|
||||
)
|
||||
);
|
||||
in
|
||||
{
|
||||
imports = [ ];
|
||||
@@ -87,22 +77,87 @@ in
|
||||
example = true;
|
||||
description = "Whether we want to install waybar.";
|
||||
};
|
||||
|
||||
waybar.config = lib.mkOption rec {
|
||||
apply = lib.recursiveUpdate default;
|
||||
inherit (settings_format) type;
|
||||
default = {
|
||||
# "height": 10, # Waybar height (to be removed for auto height)
|
||||
"modules-left" = [
|
||||
"sway/workspaces"
|
||||
"sway/mode"
|
||||
];
|
||||
"modules-center" = [ "sway/window" ];
|
||||
"modules-right" = [
|
||||
"custom/night_mode"
|
||||
"custom/temperature"
|
||||
"custom/sound"
|
||||
"custom/available_memory"
|
||||
"custom/battery"
|
||||
"idle_inhibitor"
|
||||
"custom/clock"
|
||||
"tray"
|
||||
];
|
||||
"sway/workspaces" = {
|
||||
"disable-scroll" = true;
|
||||
};
|
||||
"sway/mode" = {
|
||||
"format" = "<span style=\"italic\">{}</span>";
|
||||
};
|
||||
"sway/window" = {
|
||||
"format" = "{title}";
|
||||
};
|
||||
"idle_inhibitor" = {
|
||||
"format" = "{icon}";
|
||||
"format-icons" = {
|
||||
"activated" = "☕"; # ☕
|
||||
"deactivated" = "💤"; # ☾☁⛾⛔⏾⌛⏳💤
|
||||
};
|
||||
};
|
||||
"tray" = {
|
||||
# "icon-size" = 21;
|
||||
"spacing" = 10;
|
||||
};
|
||||
"custom/clock" = {
|
||||
"exec" = "waybar_custom_clock";
|
||||
"return-type" = "json";
|
||||
"restart-interval" = 30;
|
||||
};
|
||||
"custom/battery" = {
|
||||
"exec" = "waybar_custom_battery";
|
||||
"return-type" = "json";
|
||||
"restart-interval" = 30;
|
||||
};
|
||||
"custom/available_memory" = {
|
||||
"exec" = "waybar_custom_available_memory";
|
||||
"return-type" = "json";
|
||||
"restart-interval" = 30;
|
||||
};
|
||||
"custom/sound" = {
|
||||
"exec" = "waybar_custom_sound";
|
||||
"return-type" = "json";
|
||||
"restart-interval" = 30;
|
||||
};
|
||||
"custom/temperature" = {
|
||||
"exec" = "waybar_custom_temperature";
|
||||
"return-type" = "json";
|
||||
"restart-interval" = 30;
|
||||
};
|
||||
"custom/night_mode" = {
|
||||
"exec" = "waybar_night_mode";
|
||||
"return-type" = "json";
|
||||
"restart-interval" = 30;
|
||||
"on-click" = "pkill -USR1 -f waybar_night_mode";
|
||||
};
|
||||
};
|
||||
example = null;
|
||||
description = "Waybar's config in nix form.";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf (config.me.waybar.enable && config.me.graphical) {
|
||||
environment.systemPackages = with pkgs; [
|
||||
waybar
|
||||
waybar_available_memory
|
||||
waybar_battery
|
||||
waybar_clock
|
||||
waybar_night_mode
|
||||
waybar_sound
|
||||
waybar_temperature
|
||||
python3 # for clock TODO python should not be in the system packages, maybe switch to a venv? ref https://nixos.wiki/wiki/Python
|
||||
bc # for temperature and sound
|
||||
jq # for memory, battery, sound, night mode, and temperature
|
||||
upower # for battery
|
||||
wlsunset # for night mode
|
||||
];
|
||||
|
||||
me.swayIncludes = [
|
||||
@@ -111,13 +166,31 @@ in
|
||||
|
||||
services.upower.enable = true; # for battery
|
||||
|
||||
me.install.user.talexander.file = {
|
||||
".config/waybar/config" = {
|
||||
source = ./files/waybar_config.json;
|
||||
};
|
||||
".config/waybar/style.css" = {
|
||||
source = ./files/style.css;
|
||||
};
|
||||
};
|
||||
nixpkgs.overlays = [
|
||||
(final: prev: {
|
||||
waybar = pkgs.symlinkJoin {
|
||||
name = prev.waybar.name;
|
||||
paths = [ prev.waybar ];
|
||||
buildInputs = [ pkgs.makeWrapper ];
|
||||
postBuild = ''
|
||||
wrapProgram $out/bin/waybar --prefix PATH : ${
|
||||
lib.makeBinPath [
|
||||
waybar_available_memory
|
||||
waybar_battery
|
||||
waybar_clock
|
||||
waybar_night_mode
|
||||
waybar_sound
|
||||
waybar_temperature
|
||||
final.python3 # for clock TODO python should not be in the system packages, maybe switch to a venv? ref https://nixos.wiki/wiki/Python
|
||||
final.bc # for temperature and sound
|
||||
final.jq # for memory, battery, sound, night mode, and temperature
|
||||
final.upower # for battery
|
||||
final.wlsunset # for night mode
|
||||
]
|
||||
}
|
||||
'';
|
||||
};
|
||||
})
|
||||
];
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user