This repository has no description
0

Configure Feed

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

superconfig / tools / workspace-manager / flake-module.nix
6.4 kB 207 lines
1{ self, ... }: 2{ 3 flake.wrapperModules.workspace-manager = 4 { 5 config, 6 lib, 7 pkgs, 8 ... 9 }: 10 let 11 cfg = config.lass.workspace-manager; 12 13 workspaceType = lib.types.submodule { 14 options = { 15 directory = lib.mkOption { 16 type = lib.types.str; 17 description = "Directory to use for this workspace"; 18 }; 19 }; 20 }; 21 22 # Generate a directory with JSON files for each declared workspace 23 systemConfigDir = pkgs.linkFarm "workspace-manager-configs" ( 24 lib.mapAttrsToList (name: ws: { 25 name = "${name}.json"; 26 path = pkgs.writeText "${name}.json" (builtins.toJSON { inherit (ws) directory; }); 27 }) cfg.workspaces 28 ); 29 in 30 { 31 options.lass.workspace-manager = { 32 enable = lib.mkEnableOption "workspace manager daemon for sway"; 33 34 package = lib.mkOption { 35 type = lib.types.package; 36 default = self.packages.${pkgs.system}.workspace-manager-daemon; 37 description = "The workspace-manager-daemon package to use"; 38 }; 39 40 workspaces = lib.mkOption { 41 type = lib.types.attrsOf workspaceType; 42 default = { }; 43 description = "Declarative workspace configurations (take precedence over user configs)"; 44 example = lib.literalExpression '' 45 { 46 dev = { directory = "/home/user/src/myproject"; }; 47 music = { directory = "/home/user/Music"; }; 48 } 49 ''; 50 }; 51 52 configDir = lib.mkOption { 53 type = lib.types.str; 54 default = "~/workspaces"; 55 description = "Directory containing user workspace configuration files"; 56 }; 57 58 defaultDirectory = lib.mkOption { 59 type = lib.types.str; 60 default = "~"; 61 description = "Default directory for workspaces without configuration"; 62 }; 63 }; 64 65 config = lib.mkIf cfg.enable { 66 systemd.user.services.workspace-manager = { 67 description = "Workspace Manager Daemon"; 68 partOf = [ "sway-session.target" ]; 69 wantedBy = [ "sway-session.target" ]; 70 serviceConfig = { 71 Type = "simple"; 72 ExecStart = "${cfg.package}/bin/workspace-manager-daemon"; 73 Restart = "on-failure"; 74 RestartSec = 5; 75 Environment = [ 76 "WORKSPACE_MANAGER_CONFIG_DIR=${cfg.configDir}" 77 "WORKSPACE_MANAGER_SYSTEM_CONFIG_DIR=${systemConfigDir}" 78 "WORKSPACE_MANAGER_DEFAULT_DIR=${cfg.defaultDirectory}" 79 ]; 80 }; 81 }; 82 }; 83 }; 84 85 perSystem = 86 { 87 pkgs, 88 ... 89 }: 90 let 91 python = pkgs.python3; 92 in 93 { 94 packages.workspace-manager = 95 (pkgs.writeShellApplication { 96 name = "workspace-manager"; 97 runtimeInputs = [ 98 pkgs.socat 99 pkgs.jq 100 ]; 101 text = builtins.readFile ./workspace-manager.sh; 102 }).overrideAttrs 103 { passthru.usage = builtins.readFile ./usage.kdl; }; 104 105 packages.workspace-menu = pkgs.writeShellApplication { 106 name = "workspace-menu"; 107 runtimeInputs = [ 108 pkgs.sway 109 pkgs.jq 110 pkgs.rofi 111 pkgs.libnotify 112 pkgs.kitty 113 pkgs.findutils 114 pkgs.gnused 115 pkgs.coreutils 116 pkgs.gnugrep 117 pkgs.firefox 118 ]; 119 text = builtins.readFile ./workspace-menu.sh; 120 }; 121 122 packages.workspace-manager-daemon = pkgs.stdenv.mkDerivation { 123 pname = "workspace-manager-daemon"; 124 version = "0.1.0"; 125 src = ./.; 126 nativeBuildInputs = [ 127 pkgs.makeWrapper 128 pkgs.ruff 129 python.pkgs.mypy 130 ]; 131 doCheck = true; 132 checkPhase = '' 133 runHook preCheck 134 ruff check daemon.py 135 ruff format --check daemon.py 136 mypy --strict daemon.py 137 runHook postCheck 138 ''; 139 installPhase = '' 140 runHook preInstall 141 mkdir -p $out/bin 142 cp daemon.py $out/bin/workspace-manager-daemon 143 chmod +x $out/bin/workspace-manager-daemon 144 wrapProgram $out/bin/workspace-manager-daemon \ 145 --prefix PATH : ${python}/bin:${pkgs.sway}/bin 146 runHook postInstall 147 ''; 148 meta.mainProgram = "workspace-manager-daemon"; 149 }; 150 151 # Open Firefox for the current workspace 152 packages.workspace-browser = pkgs.writeShellScriptBin "workspace-browser" '' 153 exec firefox "$@" 154 ''; 155 156 # Native messaging host for the workspace-tabs Firefox extension 157 packages.workspace-tabs-native-host = pkgs.stdenv.mkDerivation { 158 pname = "workspace-tabs-native-host"; 159 version = "0.1.0"; 160 src = ./.; 161 nativeBuildInputs = [ 162 pkgs.makeWrapper 163 pkgs.ruff 164 python.pkgs.mypy 165 ]; 166 doCheck = true; 167 checkPhase = '' 168 runHook preCheck 169 ruff check workspace-tabs-host.py 170 ruff format --check workspace-tabs-host.py 171 mypy --strict workspace-tabs-host.py 172 runHook postCheck 173 ''; 174 installPhase = '' 175 runHook preInstall 176 mkdir -p $out/bin $out/lib/mozilla/native-messaging-hosts 177 cp workspace-tabs-host.py $out/bin/workspace-tabs-host 178 chmod +x $out/bin/workspace-tabs-host 179 wrapProgram $out/bin/workspace-tabs-host \ 180 --prefix PATH : ${python}/bin:${pkgs.sway}/bin 181 182 cat > $out/lib/mozilla/native-messaging-hosts/workspace_tabs.json <<EOF 183 { 184 "name": "workspace_tabs", 185 "description": "Native messaging host for Workspace Tabs extension", 186 "path": "$out/bin/workspace-tabs-host", 187 "type": "stdio", 188 "allowed_extensions": ["workspace-tabs@workspace-manager"] 189 } 190 EOF 191 runHook postInstall 192 ''; 193 }; 194 195 # Firefox extension for workspace tab management (packaged as .xpi) 196 packages.workspace-tabs-extension = 197 pkgs.runCommand "workspace-tabs-extension" 198 { 199 nativeBuildInputs = [ pkgs.zip ]; 200 } 201 '' 202 mkdir -p $out 203 cd ${./firefox-extension} 204 zip -r "$out/workspace-tabs@workspace-manager.xpi" ./* 205 ''; 206 }; 207}