Monorepo for Tangled tangled.org
2

Configure Feed

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

at icy/yovxsu 15 kB View raw
1{ 2 description = "atproto github"; 3 4 inputs = { 5 nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; 6 fenix = { 7 url = "github:nix-community/fenix"; 8 inputs.nixpkgs.follows = "nixpkgs"; 9 }; 10 gomod2nix = { 11 url = "github:nix-community/gomod2nix"; 12 inputs.nixpkgs.follows = "nixpkgs"; 13 }; 14 flake-compat = { 15 url = "https://git.lix.systems/lix-project/flake-compat/archive/main.tar.gz"; 16 flake = false; 17 }; 18 indigo = { 19 url = "github:oppiliappan/indigo"; 20 flake = false; 21 }; 22 htmx-src = { 23 url = "https://unpkg.com/htmx.org@2.0.4/dist/htmx.min.js"; 24 flake = false; 25 }; 26 htmx-ws-src = { 27 # strange errors in console that i can't really make out 28 # url = "https://unpkg.com/htmx.org@2.0.4/dist/ext/ws.js"; 29 url = "https://cdn.jsdelivr.net/npm/htmx-ext-ws@2.0.2"; 30 flake = false; 31 }; 32 lucide-src = { 33 url = "https://github.com/lucide-icons/lucide/releases/download/0.536.0/lucide-icons-0.536.0.zip"; 34 flake = false; 35 }; 36 inter-fonts-src = { 37 url = "https://github.com/rsms/inter/releases/download/v4.1/Inter-4.1.zip"; 38 flake = false; 39 }; 40 actor-typeahead-src = { 41 url = "git+https://tangled.org/@jakelazaroff.com/actor-typeahead"; 42 flake = false; 43 }; 44 mermaid-src = { 45 url = "https://cdn.jsdelivr.net/npm/mermaid@11.12.3/dist/mermaid.min.js"; 46 flake = false; 47 }; 48 ibm-plex-mono-src = { 49 url = "https://github.com/IBM/plex/releases/download/%40ibm%2Fplex-mono%401.1.0/ibm-plex-mono.zip"; 50 flake = false; 51 }; 52 sqlite-lib-src = { 53 url = "https://sqlite.org/2024/sqlite-amalgamation-3450100.zip"; 54 flake = false; 55 }; 56 }; 57 58 outputs = { 59 self, 60 nixpkgs, 61 fenix, 62 gomod2nix, 63 indigo, 64 htmx-src, 65 htmx-ws-src, 66 lucide-src, 67 inter-fonts-src, 68 sqlite-lib-src, 69 ibm-plex-mono-src, 70 actor-typeahead-src, 71 mermaid-src, 72 ... 73 }: let 74 supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]; 75 forAllSystems = nixpkgs.lib.genAttrs supportedSystems; 76 nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system}); 77 78 mkPackageSet = pkgs: 79 pkgs.lib.makeScope pkgs.newScope (self: { 80 src = let 81 fs = pkgs.lib.fileset; 82 in 83 fs.toSource { 84 root = ./.; 85 fileset = fs.difference (fs.intersection (fs.gitTracked ./.) (fs.fileFilter (file: !(file.hasExt "nix")) ./.)) (fs.maybeMissing ./.jj); 86 }; 87 buildGoApplication = 88 (self.callPackage "${gomod2nix}/builder" { 89 gomod2nix = gomod2nix.legacyPackages.${pkgs.stdenv.hostPlatform.system}.gomod2nix; 90 }).buildGoApplication; 91 rustPlatform = pkgs.makeRustPlatform { 92 inherit (fenix.packages.${pkgs.system}.stable) rustc cargo; 93 }; 94 modules = ./nix/gomod2nix.toml; 95 sqlite-lib = self.callPackage ./nix/pkgs/sqlite-lib.nix { 96 inherit sqlite-lib-src; 97 }; 98 lexgen = self.callPackage ./nix/pkgs/lexgen.nix {inherit indigo;}; 99 goat = self.callPackage ./nix/pkgs/goat.nix {inherit indigo;}; 100 appview-static-files = self.callPackage ./nix/pkgs/appview-static-files.nix { 101 inherit htmx-src htmx-ws-src lucide-src inter-fonts-src ibm-plex-mono-src actor-typeahead-src mermaid-src; 102 }; 103 appview = self.callPackage ./nix/pkgs/appview.nix {}; 104 blog = self.callPackage ./nix/pkgs/blog.nix {}; 105 docs = self.callPackage ./nix/pkgs/docs.nix { 106 inherit inter-fonts-src ibm-plex-mono-src lucide-src; 107 inherit (pkgs) pagefind; 108 }; 109 spindle = self.callPackage ./nix/pkgs/spindle.nix {}; 110 knot-unwrapped = self.callPackage ./nix/pkgs/knot-unwrapped.nix {}; 111 knot = self.callPackage ./nix/pkgs/knot.nix {}; 112 dolly = self.callPackage ./nix/pkgs/dolly.nix {}; 113 tap = self.callPackage ./nix/pkgs/tap.nix {}; 114 knotmirror = self.callPackage ./nix/pkgs/knotmirror.nix {}; 115 bobbin = self.callPackage ./nix/pkgs/bobbin.nix {}; 116 }); 117 in { 118 overlays.default = final: prev: { 119 inherit (mkPackageSet final) lexgen goat sqlite-lib spindle knot-unwrapped knot appview docs dolly tap knotmirror bobbin; 120 }; 121 122 packages = forAllSystems (system: let 123 pkgs = nixpkgsFor.${system}; 124 packages = mkPackageSet pkgs; 125 staticPackages = mkPackageSet pkgs.pkgsStatic; 126 crossPackages = mkPackageSet pkgs.pkgsCross.gnu64.pkgsStatic; 127 in { 128 inherit 129 (packages) 130 appview 131 appview-static-files 132 blog 133 lexgen 134 goat 135 spindle 136 knot 137 knot-unwrapped 138 sqlite-lib 139 docs 140 dolly 141 tap 142 knotmirror 143 bobbin 144 ; 145 146 pkgsStatic-appview = staticPackages.appview; 147 pkgsStatic-knot = staticPackages.knot; 148 pkgsStatic-knot-unwrapped = staticPackages.knot-unwrapped; 149 pkgsStatic-spindle = staticPackages.spindle; 150 pkgsStatic-sqlite-lib = staticPackages.sqlite-lib; 151 pkgsStatic-dolly = staticPackages.dolly; 152 153 pkgsCross-gnu64-pkgsStatic-appview = crossPackages.appview; 154 pkgsCross-gnu64-pkgsStatic-knot = crossPackages.knot; 155 pkgsCross-gnu64-pkgsStatic-knot-unwrapped = crossPackages.knot-unwrapped; 156 pkgsCross-gnu64-pkgsStatic-spindle = crossPackages.spindle; 157 pkgsCross-gnu64-pkgsStatic-dolly = crossPackages.dolly; 158 159 treefmt-wrapper = pkgs.treefmt.withConfig { 160 settings.formatter = { 161 alejandra = { 162 command = pkgs.lib.getExe pkgs.alejandra; 163 includes = ["*.nix"]; 164 }; 165 166 gofmt = { 167 command = pkgs.lib.getExe' pkgs.go "gofmt"; 168 options = ["-w"]; 169 includes = ["*.go"]; 170 }; 171 172 rustfmt = { 173 command = pkgs.lib.getExe' fenix.packages.${system}.stable.rustfmt "rustfmt"; 174 options = ["--edition" "2024"]; 175 includes = ["*.rs"]; 176 excludes = ["**/src/_lex/**"]; 177 }; 178 179 # prettier = let 180 # wrapper = pkgs.runCommandLocal "prettier-wrapper" {nativeBuildInputs = [pkgs.makeWrapper];} '' 181 # makeWrapper ${pkgs.prettier}/bin/prettier "$out" --add-flags "--plugin=${pkgs.prettier-plugin-go-template}/lib/node_modules/prettier-plugin-go-template/lib/index.js" 182 # ''; 183 # in { 184 # command = wrapper; 185 # options = ["-w"]; 186 # includes = ["*.html"]; 187 # # causes Go template plugin errors: https://github.com/NiklasPor/prettier-plugin-go-template/issues/120 188 # excludes = ["appview/pages/templates/layouts/repobase.html" "appview/pages/templates/repo/tags.html"]; 189 # }; 190 }; 191 }; 192 }); 193 defaultPackage = forAllSystems (system: self.packages.${system}.appview); 194 devShells = forAllSystems (system: let 195 pkgs = nixpkgsFor.${system}; 196 packages' = self.packages.${system}; 197 staticShell = args: 198 (pkgs.mkShell.override { 199 stdenv = pkgs.pkgsStatic.stdenv; 200 }) (args 201 // { 202 nativeBuildInputs = 203 args.nativeBuildInputs 204 ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ 205 pkgs.darwin.cctools 206 ]; 207 }); 208 in { 209 default = staticShell { 210 nativeBuildInputs = [ 211 pkgs.go 212 pkgs.air 213 pkgs.gopls 214 pkgs.httpie 215 pkgs.litecli 216 pkgs.websocat 217 pkgs.tailwindcss 218 pkgs.nixos-shell 219 pkgs.redis 220 pkgs.worker-build 221 pkgs.cargo-generate 222 (fenix.packages.${system}.combine [ 223 fenix.packages.${system}.stable.cargo 224 fenix.packages.${system}.stable.rustc 225 fenix.packages.${system}.stable.rust-src 226 fenix.packages.${system}.stable.clippy 227 fenix.packages.${system}.stable.rustfmt 228 fenix.packages.${system}.targets.wasm32-unknown-unknown.stable.rust-std 229 ]) 230 pkgs.coreutils # for those of us who are on systems that use busybox (alpine) 231 packages'.lexgen 232 packages'.treefmt-wrapper 233 packages'.tap 234 ]; 235 shellHook = '' 236 mkdir -p appview/pages/static 237 # temporary self-heal for workspaces that copied static assets as read-only 238 [ -d appview/pages/static/icons ] && [ ! -w appview/pages/static/icons ] && chmod -R u+rwX appview/pages/static 239 # no preserve is needed because watch-tailwind will want to be able to overwrite 240 cp -fr --no-preserve=ownership,mode ${packages'.appview-static-files}/* appview/pages/static 241 export TANGLED_OAUTH_CLIENT_KID="$(date +%s)" 242 export TANGLED_OAUTH_CLIENT_SECRET="$(${packages'.goat}/bin/goat key generate -t P-256 | grep -A1 "Secret Key" | tail -n1 | awk '{print $1}')" 243 # Make xcrun (Nix stub) able to find ld from the system Command Line Tools. 244 # Without this, worker-build/cargo fails with "error: tool 'ld' not found". 245 if [ -d /Library/Developer/CommandLineTools/usr/bin ]; then 246 export PATH=/Library/Developer/CommandLineTools/usr/bin:$PATH 247 fi 248 ''; 249 env.CGO_ENABLED = 1; 250 }; 251 }); 252 apps = forAllSystems (system: let 253 pkgs = nixpkgsFor."${system}"; 254 packages' = self.packages.${system}; 255 air-watcher = name: arg: 256 pkgs.writeShellScriptBin "run" 257 '' 258 export PATH=${pkgs.go}/bin:$PATH 259 ${pkgs.air}/bin/air -c ./.air/${name}.toml \ 260 -build.args_bin "${arg}" 261 ''; 262 tailwind-watcher = 263 pkgs.writeShellScriptBin "run" 264 '' 265 export BROWSERSLIST_IGNORE_OLD_DATA=true 266 ${pkgs.tailwindcss}/bin/tailwindcss --watch=always -i input.css -o ./appview/pages/static/tw.css 267 ''; 268 in { 269 watch-appview = { 270 type = "app"; 271 program = toString (pkgs.writeShellScript "watch-appview" '' 272 echo "copying static files to appview/pages/static..." 273 mkdir -p appview/pages/static 274 ${pkgs.coreutils}/bin/cp -fr --no-preserve=ownership,mode ${packages'.appview-static-files}/* appview/pages/static 275 ${air-watcher "appview" ""}/bin/run 276 ''); 277 }; 278 watch-knot = { 279 type = "app"; 280 program = ''${air-watcher "knot" "server"}/bin/run''; 281 }; 282 watch-spindle = { 283 type = "app"; 284 program = ''${air-watcher "spindle" ""}/bin/run''; 285 }; 286 watch-blog = { 287 type = "app"; 288 program = toString (pkgs.writeShellScript "watch-blog" '' 289 echo "copying static files to appview/pages/static..." 290 mkdir -p appview/pages/static 291 ${pkgs.coreutils}/bin/cp -fr --no-preserve=ownership,mode ${packages'.appview-static-files}/* appview/pages/static 292 ${air-watcher "blog" "serve"}/bin/run 293 ''); 294 }; 295 watch-tailwind = { 296 type = "app"; 297 program = ''${tailwind-watcher}/bin/run''; 298 }; 299 serve-docs = { 300 type = "app"; 301 program = toString (pkgs.writeShellScript "serve-docs" '' 302 echo "building docs..." 303 docsOut=$(nix build --no-link --print-out-paths .#docs) 304 echo "serving docs at http://localhost:1414" 305 cd "$docsOut" 306 exec ${pkgs.python3}/bin/python3 -m http.server 1414 307 ''); 308 }; 309 vm = let 310 guestSystem = 311 if pkgs.stdenv.hostPlatform.isAarch64 312 then "aarch64-linux" 313 else "x86_64-linux"; 314 in { 315 type = "app"; 316 program = 317 (pkgs.writeShellApplication { 318 name = "launch-vm"; 319 text = '' 320 rootDir=$(jj --ignore-working-copy root || git rev-parse --show-toplevel) || (echo "error: can't find repo root?"; exit 1) 321 cd "$rootDir" 322 323 mkdir -p nix/vm-data/{knot,repos,spindle,spindle-logs} 324 325 export TANGLED_VM_DATA_DIR="$rootDir/nix/vm-data" 326 exec ${pkgs.lib.getExe 327 (import ./nix/vm.nix { 328 inherit nixpkgs self; 329 system = guestSystem; 330 hostSystem = system; 331 }).config.system.build.vm} 332 ''; 333 }) 334 + /bin/launch-vm; 335 }; 336 gomod2nix = { 337 type = "app"; 338 program = toString (pkgs.writeShellScript "gomod2nix" '' 339 ${gomod2nix.legacyPackages.${system}.gomod2nix}/bin/gomod2nix generate --outdir ./nix 340 ''); 341 }; 342 lexgen = { 343 type = "app"; 344 program = 345 (pkgs.writeShellApplication { 346 name = "lexgen"; 347 text = '' 348 if ! command -v lexgen > /dev/null; then 349 echo "error: must be executed from devshell" 350 exit 1 351 fi 352 353 rootDir=$(jj --ignore-working-copy root || git rev-parse --show-toplevel) || (echo "error: can't find repo root?"; exit 1) 354 cd "$rootDir" 355 356 rm -f api/tangled/* 357 lexgen --build-file lexicon-build-config.json lexicons 358 sed -i.bak 's/\tutil/\/\/\tutil/' api/tangled/* 359 # lexgen generates incomplete Marshaler/Unmarshaler for union types 360 find api/tangled/*.go -not -name "cbor_gen.go" -exec \ 361 sed -i '/^func.*\(MarshalCBOR\|UnmarshalCBOR\)/,/^}/ s/^/\/\/ /' {} + 362 ${pkgs.gotools}/bin/goimports -w api/tangled/* 363 go run ./cmd/cborgen/ 364 lexgen --build-file lexicon-build-config.json lexicons 365 rm api/tangled/*.bak 366 ''; 367 }) 368 + /bin/lexgen; 369 }; 370 }); 371 372 nixosModules.appview = { 373 lib, 374 pkgs, 375 ... 376 }: { 377 imports = [./nix/modules/appview.nix]; 378 379 services.tangled.appview.package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.appview; 380 }; 381 nixosModules.knotmirror = { 382 lib, 383 pkgs, 384 ... 385 }: { 386 imports = [./nix/modules/knotmirror.nix]; 387 388 services.tangled.knotmirror.tap-package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.tap; 389 services.tangled.knotmirror.package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.knotmirror; 390 }; 391 nixosModules.knot = { 392 lib, 393 pkgs, 394 ... 395 }: { 396 imports = [./nix/modules/knot.nix]; 397 398 services.tangled.knot.package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.knot; 399 }; 400 nixosModules.spindle = { 401 lib, 402 pkgs, 403 ... 404 }: { 405 imports = [./nix/modules/spindle.nix]; 406 407 services.tangled.spindle.package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.spindle; 408 }; 409 410 formatter = forAllSystems (system: self.packages.${system}.treefmt-wrapper); 411 }; 412}