1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-18 09:09:45 +01:00
home-manager/modules/services/window-managers/bspwm/default.nix
Robert Helgesson 5f433eb164
Move platform check into modules
Before, loading a module would be guarded by an optional platform
condition. This made it possible to avoid loading and evaluating a
module if it did not support the host platform.

Unfortunately, this made it impossible to share a single configuration
between GNU/Linux and Darwin hosts, which some wish to do.

This removes the conditional load and instead inserts host platform
assertions in the modules that are platform specific.

Fixes #1906
2021-07-18 20:43:22 +02:00

71 lines
1.9 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.xsession.windowManager.bspwm;
camelToSnake =
builtins.replaceStrings upperChars (map (c: "_${c}") lowerChars);
formatMonitor = monitor: desktops:
"bspc monitor ${escapeShellArg monitor} -d ${escapeShellArgs desktops}";
formatValue = v:
if isList v then
concatMapStringsSep "," formatValue v
else if isBool v then
if v then "on" else "off"
else if isInt v || isFloat v then
toString v
else if isString v then
v
else
throw "unsupported type"; # should not happen
formatSetting = n: v: "bspc config ${escapeShellArgs [ n (formatValue v) ]}";
formatRule = target: directives:
let
formatDirective = n: v: "${camelToSnake n}=${formatValue v}";
directivesStr = escapeShellArgs (mapAttrsToList formatDirective
(filterAttrs (n: v: v != null) directives));
in "bspc rule -a ${escapeShellArg target} ${directivesStr}";
formatStartupProgram = s: "${s} &";
in {
meta.maintainers = [ maintainers.ncfavier ];
options = import ./options.nix { inherit pkgs lib; };
config = mkIf cfg.enable {
assertions = [
(hm.assertions.assertPlatform "xsession.windowManager.bspwm" pkgs
platforms.linux)
];
home.packages = [ cfg.package ];
xdg.configFile."bspwm/bspwmrc".source = pkgs.writeShellScript "bspwmrc" ''
${concatStringsSep "\n" (mapAttrsToList formatMonitor cfg.monitors)}
${concatStringsSep "\n" (mapAttrsToList formatSetting cfg.settings)}
bspc rule -r '*'
${concatStringsSep "\n" (mapAttrsToList formatRule cfg.rules)}
# java gui fixes
export _JAVA_AWT_WM_NONREPARENTING=1
bspc rule -a sun-awt-X11-XDialogPeer state=floating
${cfg.extraConfig}
${concatMapStringsSep "\n" formatStartupProgram cfg.startupPrograms}
'';
xsession.windowManager.command =
"${cfg.package}/bin/bspwm -c ${config.xdg.configHome}/bspwm/bspwmrc";
};
}