This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / 3modules / workspace-manager.nix
3.4 kB 112 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) directory on_enter on_leave on_create; 42 } 43 ); 44 }) cfg.workspaces 45 ); 46in 47{ 48 options.lass.workspace-manager = { 49 enable = lib.mkEnableOption "workspace manager daemon for sway"; 50 51 package = lib.mkOption { 52 type = lib.types.package; 53 default = self.packages.${pkgs.system}.workspace-manager-daemon; 54 description = "The workspace-manager-daemon package to use"; 55 }; 56 57 workspaces = lib.mkOption { 58 type = lib.types.attrsOf workspaceType; 59 default = { }; 60 description = "Declarative workspace configurations (take precedence over user configs)"; 61 example = lib.literalExpression '' 62 { 63 dev = { 64 directory = "/home/user/src/myproject"; 65 on_enter = [ "notify-send 'Entered dev workspace'" ]; 66 }; 67 music = { 68 directory = "/home/user/Music"; 69 }; 70 } 71 ''; 72 }; 73 74 configDir = lib.mkOption { 75 type = lib.types.str; 76 default = "~/workspaces"; 77 description = "Directory containing user workspace configuration files"; 78 }; 79 80 defaultDirectory = lib.mkOption { 81 type = lib.types.str; 82 default = "~"; 83 description = "Default directory for workspaces without configuration"; 84 }; 85 86 terminalCommand = lib.mkOption { 87 type = lib.types.str; 88 default = "kitty"; 89 description = "Terminal emulator to use for on_create commands. Must support '-T title' for setting the window title."; 90 }; 91 }; 92 93 config = lib.mkIf cfg.enable { 94 systemd.user.services.workspace-manager = { 95 description = "Workspace Manager Daemon"; 96 partOf = [ "sway-session.target" ]; 97 wantedBy = [ "sway-session.target" ]; 98 serviceConfig = { 99 Type = "simple"; 100 ExecStart = "${cfg.package}/bin/workspace-manager-daemon"; 101 Restart = "on-failure"; 102 RestartSec = 5; 103 Environment = [ 104 "WORKSPACE_MANAGER_CONFIG_DIR=${cfg.configDir}" 105 "WORKSPACE_MANAGER_SYSTEM_CONFIG_DIR=${systemConfigDir}" 106 "WORKSPACE_MANAGER_DEFAULT_DIR=${cfg.defaultDirectory}" 107 "WORKSPACE_MANAGER_TERMINAL=${cfg.terminalCommand}" 108 ]; 109 }; 110 }; 111 }; 112}