flake.nix

  1{
  2  description = "RTW - Adventure Motorcycle Trip Planning App";
  3
  4  inputs = {
  5    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  6    bug.url = "git+https://git.kilimanjaro.io/bug";
  7    concurrently.url = "git+https://git.kilimanjaro.io/concurrently";
  8    vibe.url = "git+https://git.kilimanjaro.io/vibe";
  9    ygo = {
 10      url = "git+https://git.kilimanjaro.io/ygo";
 11      flake = false;
 12    };
 13  };
 14
 15  outputs = { self, nixpkgs, bug, concurrently, vibe, ygo }:
 16    let
 17      systems = [ "x86_64-linux" ];
 18      forEachSystem = nixpkgs.lib.genAttrs systems;
 19
 20      y-sweet-package = { pkgs, lib, fetchFromGitHub, rustPlatform }:
 21        rustPlatform.buildRustPackage rec {
 22          pname = "y-sweet";
 23          version = "0.9.1";
 24
 25          src = fetchFromGitHub {
 26            owner = "jamsocket";
 27            repo = "y-sweet";
 28            tag = "v${version}";
 29            hash = "sha256-Axt5wFvHZFB+A69NBf5IkFqGE79B0jFUl4vW+g0m34k=";
 30          };
 31
 32          # The crate is in a workspace under crates/
 33          sourceRoot = "source/crates";
 34
 35          # Build the y-sweet binary specifically
 36          cargoBuildFlags = [ "-p" "y-sweet" ];
 37
 38          # Use cargoHash - computed from cargo vendor output
 39          cargoHash = "sha256-UJOdJ45rz+nnpDQUC0bvFXiqZ8W9mjFDaCVcjacHyyY=";
 40
 41          meta = {
 42            description = "A realtime CRDT-based document store, backed by S3";
 43            homepage = "https://y-sweet.dev";
 44            license = lib.licenses.mit;
 45            mainProgram = "y-sweet";
 46          };
 47        };
 48
 49      rtw-package = { pkgs, lib, buildGoModule, ygo }:
 50        buildGoModule {
 51          pname = "rtw";
 52          version = "2026.06.040726";
 53
 54          src = ./.;
 55
 56          buildInputs = [
 57            pkgs.brotli
 58          ];
 59
 60          # Go module lives in server/
 61          modRoot = "server";
 62
 63          # Build only the server command
 64          subPackages = [ "cmd/rtw" ];
 65
 66          # Disable workspace so Go ignores ../waldo and ../ygo paths that
 67          # don't exist in the Nix sandbox.
 68          GOWORK = "off";
 69          env.CGO_ENABLED = "1";
 70
 71          # Compute by running: nix build .#rtw
 72          # Then copy the hash from the error message
 73          vendorHash = "sha256-QPAYsfLvWdEt0PHc2UCJjpgW07nShaht394unskjjn8=";
 74
 75          doCheck = false;
 76
 77          overrideModAttrs = old: {
 78            GOWORK = "off";
 79          };
 80
 81          # postConfigure runs after the vendor directory is set up from goModules
 82          # but is NOT inherited by the goModules derivation (unlike preBuild).
 83          postConfigure = ''
 84            # go mod vendor does not copy the ygo lib/ directory (C headers and
 85            # static libraries) because it contains no Go files.  We inject them
 86            # from the full git source here so CGo can find libyrs.h and libyrs.a.
 87            chmod -R +w vendor
 88            mkdir -p vendor/git.kilimanjaro.io/ygo/lib
 89            cp -r ${ygo}/lib/* vendor/git.kilimanjaro.io/ygo/lib/
 90          '';
 91
 92          meta = {
 93            description = "RTW adventure motorcycle trip planning server";
 94            license = lib.licenses.agpl3Plus;
 95            homepage = "https://kilimanjaro.io/rtw";
 96            mainProgram = "rtw";
 97          };
 98        };
 99    in
100    {
101      packages = forEachSystem (system:
102        let
103          pkgs = nixpkgs.legacyPackages.${system};
104        in
105        {
106          y-sweet = pkgs.callPackage y-sweet-package {};
107          rtw = pkgs.callPackage rtw-package { inherit ygo; };
108          default = self.packages.${system}.rtw;
109        }
110      );
111
112      devShells = forEachSystem (system:
113        let
114          pkgs = nixpkgs.legacyPackages.${system};
115        in
116        {
117          default = pkgs.mkShell {
118            buildInputs = [
119              pkgs.nodejs
120              pkgs.corepack
121              pkgs.go
122              pkgs.coreutils
123              pkgs.bash
124              pkgs.gnumake
125              pkgs.brotli
126              pkgs.esbuild
127              pkgs.golangci-lint
128              bug.packages.${system}.default
129              concurrently.packages.${system}.default
130              vibe.packages.${system}.default
131            ];
132          };
133        }
134      );
135    };
136}