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
2.8 kB 100 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 }; 28 }; 29 30 # Generate a directory with JSON files for each declared workspace 31 systemConfigDir = pkgs.linkFarm "workspace-manager-configs" ( 32 lib.mapAttrsToList (name: ws: { 33 name = "${name}.json"; 34 path = pkgs.writeText "${name}.json" ( 35 builtins.toJSON { 36 inherit (ws) directory on_enter on_leave; 37 } 38 ); 39 }) cfg.workspaces 40 ); 41in 42{ 43 options.lass.workspace-manager = { 44 enable = lib.mkEnableOption "workspace manager daemon for sway"; 45 46 package = lib.mkOption { 47 type = lib.types.package; 48 default = self.packages.${pkgs.system}.workspace-manager-daemon; 49 description = "The workspace-manager-daemon package to use"; 50 }; 51 52 workspaces = lib.mkOption { 53 type = lib.types.attrsOf workspaceType; 54 default = { }; 55 description = "Declarative workspace configurations (take precedence over user configs)"; 56 example = lib.literalExpression '' 57 { 58 dev = { 59 directory = "/home/user/src/myproject"; 60 on_enter = [ "notify-send 'Entered dev workspace'" ]; 61 }; 62 music = { 63 directory = "/home/user/Music"; 64 }; 65 } 66 ''; 67 }; 68 69 configDir = lib.mkOption { 70 type = lib.types.str; 71 default = "~/workspaces"; 72 description = "Directory containing user workspace configuration files"; 73 }; 74 75 defaultDirectory = lib.mkOption { 76 type = lib.types.str; 77 default = "~"; 78 description = "Default directory for workspaces without configuration"; 79 }; 80 }; 81 82 config = lib.mkIf cfg.enable { 83 systemd.user.services.workspace-manager = { 84 description = "Workspace Manager Daemon"; 85 partOf = [ "sway-session.target" ]; 86 wantedBy = [ "sway-session.target" ]; 87 serviceConfig = { 88 Type = "simple"; 89 ExecStart = "${cfg.package}/bin/workspace-manager-daemon"; 90 Restart = "on-failure"; 91 RestartSec = 5; 92 Environment = [ 93 "WORKSPACE_MANAGER_CONFIG_DIR=${cfg.configDir}" 94 "WORKSPACE_MANAGER_SYSTEM_CONFIG_DIR=${systemConfigDir}" 95 "WORKSPACE_MANAGER_DEFAULT_DIR=${cfg.defaultDirectory}" 96 ]; 97 }; 98 }; 99 }; 100}