This repository has no description
3.5 kB
117 lines
1{
2 config,
3 lib,
4 pkgs,
5 self,
6 ...
7}:
8let
9 cfg = config.lass.workspace-manager;
10
11 workspaceType = lib.types.submodule {
12 options = {
13 directory = lib.mkOption {
14 type = lib.types.str;
15 description = "Directory to use for this workspace";
16 };
17 on_enter = lib.mkOption {
18 type = lib.types.listOf lib.types.str;
19 default = [ ];
20 description = "Commands to run when entering this workspace";
21 };
22 on_leave = lib.mkOption {
23 type = lib.types.listOf lib.types.str;
24 default = [ ];
25 description = "Commands to run when leaving this workspace";
26 };
27 on_create = lib.mkOption {
28 type = lib.types.listOf lib.types.str;
29 default = [ ];
30 description = "Commands to run in a tmux session when the workspace is first entered. Each command gets its own tmux window with visible logs. Reattach with: tmux attach -t ws-<name>";
31 };
32 };
33 };
34
35 # Generate a directory with JSON files for each declared workspace
36 systemConfigDir = pkgs.linkFarm "workspace-manager-configs" (
37 lib.mapAttrsToList (name: ws: {
38 name = "${name}.json";
39 path = pkgs.writeText "${name}.json" (
40 builtins.toJSON {
41 inherit (ws)
42 directory
43 on_enter
44 on_leave
45 on_create
46 ;
47 }
48 );
49 }) cfg.workspaces
50 );
51in
52{
53 options.lass.workspace-manager = {
54 enable = lib.mkEnableOption "workspace manager daemon for sway";
55
56 package = lib.mkOption {
57 type = lib.types.package;
58 default = self.packages.${pkgs.system}.workspace-manager-daemon;
59 description = "The workspace-manager-daemon package to use";
60 };
61
62 workspaces = lib.mkOption {
63 type = lib.types.attrsOf workspaceType;
64 default = { };
65 description = "Declarative workspace configurations (take precedence over user configs)";
66 example = lib.literalExpression ''
67 {
68 dev = {
69 directory = "/home/user/src/myproject";
70 on_enter = [ "notify-send 'Entered dev workspace'" ];
71 };
72 music = {
73 directory = "/home/user/Music";
74 };
75 }
76 '';
77 };
78
79 configDir = lib.mkOption {
80 type = lib.types.str;
81 default = "~/workspaces";
82 description = "Directory containing user workspace configuration files";
83 };
84
85 defaultDirectory = lib.mkOption {
86 type = lib.types.str;
87 default = "~";
88 description = "Default directory for workspaces without configuration";
89 };
90
91 terminalCommand = lib.mkOption {
92 type = lib.types.str;
93 default = "kitty";
94 description = "Terminal emulator to use for on_create commands. Must support '-T title' for setting the window title.";
95 };
96 };
97
98 config = lib.mkIf cfg.enable {
99 systemd.user.services.workspace-manager = {
100 description = "Workspace Manager Daemon";
101 partOf = [ "sway-session.target" ];
102 wantedBy = [ "sway-session.target" ];
103 serviceConfig = {
104 Type = "simple";
105 ExecStart = "${cfg.package}/bin/workspace-manager-daemon";
106 Restart = "on-failure";
107 RestartSec = 5;
108 Environment = [
109 "WORKSPACE_MANAGER_CONFIG_DIR=${cfg.configDir}"
110 "WORKSPACE_MANAGER_SYSTEM_CONFIG_DIR=${systemConfigDir}"
111 "WORKSPACE_MANAGER_DEFAULT_DIR=${cfg.defaultDirectory}"
112 "WORKSPACE_MANAGER_TERMINAL=${cfg.terminalCommand}"
113 ];
114 };
115 };
116 };
117}