diff --git a/hosts/modules/gui/sxmo/bonsai.nix b/hosts/common/programs/bonsai.nix similarity index 57% rename from hosts/modules/gui/sxmo/bonsai.nix rename to hosts/common/programs/bonsai.nix index 4943da7b3..1fe7cf01c 100644 --- a/hosts/modules/gui/sxmo/bonsai.nix +++ b/hosts/common/programs/bonsai.nix @@ -1,7 +1,7 @@ # bonsai docs: { config, lib, pkgs, ... }: let - cfg = config.sane.gui.sxmo.bonsaid; + cfg = config.sane.programs.bonsai.config; delayType = with lib; types.submodule { options = { @@ -88,74 +88,43 @@ let mergeOneOption loc defs ; }; - - # transitionType = with lib; types.submodule { - # options = { - # type = mkOption { - # type = types.enum [ "delay" "event" "exec" ]; - # }; - # delay_duration = mkOption { - # type = types.nullOr types.int; - # default = null; - # description = '' - # used for "delay" types only. - # nanoseconds until the event is finalized. - # ''; - # }; - # event_name = mkOption { - # type = types.nullOr types.str; - # default = null; - # description = '' - # name of event which this transition applies to. - # ''; - # }; - # transitions = mkOption { - # type = types.nullOr (types.listOf transitionType); - # default = null; - # description = '' - # list of transitions out of this state. - # ''; - # }; - # command = mkOption { - # type = types.nullOr (types.listOf types.str); - # default = null; - # description = '' - # used for "exec" types only. - # command to run when the event is triggered. - # ''; - # }; - # }; - # }; in { - options = with lib; { - sane.gui.sxmo.bonsaid.package = mkOption { - type = types.package; - default = pkgs.bonsai; + sane.programs.bonsai = { + configOption = with lib; mkOption { + default = {}; + type = types.submodule { + options = { + transitions = mkOption { + type = types.listOf transitionType; + default = []; + }; + configFile = mkOption { + type = types.path; + default = pkgs.writeText "bonsai_tree.json" (builtins.toJSON cfg.transitions); + description = '' + configuration file to pass to bonsai. + usually auto-generated from the sibling options; exposed mainly for debugging or convenience. + ''; + }; + }; + }; }; - sane.gui.sxmo.bonsaid.transitions = mkOption { - type = types.listOf transitionType; - default = []; - }; - sane.gui.sxmo.bonsaid.configFile = mkOption { - type = types.path; - default = pkgs.writeText "bonsai_tree.json" (builtins.toJSON cfg.transitions); - description = '' - configuration file to pass to bonsai. - usually auto-generated from the sibling options; exposed mainly for debugging or convenience. - ''; - }; - }; - config = lib.mkIf config.sane.gui.sxmo.enable { - sane.user.services.bonsaid = { - description = "programmable input dispatcher"; + + services.bonsaid = { + description = "bonsai: programmable input dispatcher"; + after = [ "graphical-session.target" ]; + wantedBy = [ "graphical-session.target" ]; + script = '' ${pkgs.coreutils}/bin/rm -f $XDG_RUNTIME_DIR/bonsai exec ${cfg.package}/bin/bonsaid -t ${cfg.configFile} ''; - serviceConfig.Type = "simple"; - serviceConfig.Restart = "always"; - serviceConfig.RestartSec = "5s"; + serviceConfig = { + Type = "simple"; + Restart = "always"; + RestartSec = "5s"; + }; }; }; } diff --git a/hosts/common/programs/default.nix b/hosts/common/programs/default.nix index 88f41fda3..e6e78626f 100644 --- a/hosts/common/programs/default.nix +++ b/hosts/common/programs/default.nix @@ -9,6 +9,7 @@ ./assorted.nix ./audacity.nix ./bemenu.nix + ./bonsai.nix ./brave.nix ./bubblewrap.nix ./calls.nix diff --git a/hosts/modules/gui/sxmo/default.nix b/hosts/modules/gui/sxmo/default.nix index 81d1f5396..b2ebc2a4e 100644 --- a/hosts/modules/gui/sxmo/default.nix +++ b/hosts/modules/gui/sxmo/default.nix @@ -256,10 +256,6 @@ in }; }; - imports = [ - ./bonsai.nix - ]; - config = lib.mkMerge [ { sane.programs.sxmoApps = { @@ -267,6 +263,7 @@ in suggestedPrograms = [ "guiApps" "bemenu" # specifically to import its theming + "bonsai" "sfeed" # want this here so that the user's ~/.sfeed/sfeedrc gets created # "superd" # make superctl (used by sxmo) be on PATH # "sway-autoscaler" @@ -403,7 +400,6 @@ in # TODO: could use `displayManager.sessionPackages`? environment.systemPackages = [ package - pkgs.bonsai # sway (not sxmo) needs to exec `bonsaictl` by name (sxmo_swayinitconf.sh) ] ++ lib.optionals (cfg.terminal != null) [ pkgs."${cfg.terminal}" ] ++ lib.optionals (cfg.keyboard != null) [ pkgs."${cfg.keyboard}" ]; @@ -420,7 +416,7 @@ in ); - sane.gui.sxmo.bonsaid.transitions = let + sane.programs.bonsai.config.transitions = let doExec = inputName: transitions: { type = "exec"; command = [