Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T01:44:23.240Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

build.nix

399 lines · 12.8 KB · text
1{
2  pkgs,
3  system,
4  lib,
5  stdenv,
6
7  apple-sdk_15,
8  darwin,
9  darwinMinVersionHook,
10
11  cargo-about,
12  cargo-bundle,
13  crane,
14  rustPlatform,
15  rustToolchain,
16
17  copyDesktopItems,
18  envsubst,
19  fetchFromGitHub,
20  makeFontsConf,
21  makeWrapper,
22
23  alsa-lib,
24  cmake,
25  curl,
26  fontconfig,
27  freetype,
28  git,
29  glib,
30  libdrm,
31  libgbm,
32  libgit2,
33  libglvnd,
34  libva,
35  libxcomposite,
36  libxdamage,
37  libxext,
38  libxfixes,
39  libxkbcommon,
40  libxrandr,
41  lld,
42  libx11,
43  libxcb,
44  nodejs_22,
45  openssl,
46  perl,
47  pkg-config,
48  protobuf,
49  sqlite,
50  vulkan-loader,
51  wayland,
52  xorg,
53  zlib,
54  zstd,
55
56  withGLES ? false,
57  profile ? "release",
58  commitSha ? null,
59}:
60assert withGLES -> stdenv.hostPlatform.isLinux;
61let
62  mkIncludeFilter =
63    root': path: type:
64    let
65      # note: under lazy-trees this introduces an extra copy
66      root = toString root' + "/";
67      relPath = lib.removePrefix root path;
68      topLevelIncludes = [
69        "crates"
70        "assets"
71        "extensions"
72        "script"
73        "tooling"
74        "Cargo.toml"
75        ".config" # nextest?
76        ".cargo"
77      ];
78      firstComp = builtins.head (lib.path.subpath.components relPath);
79    in
80    builtins.elem firstComp topLevelIncludes;
81
82  craneLib = crane.overrideToolchain rustToolchain;
83  gpu-lib = if withGLES then libglvnd else vulkan-loader;
84  commonArgs =
85    let
86      zedCargoLock = builtins.fromTOML (builtins.readFile ../crates/zed/Cargo.toml);
87      stdenv' = stdenv;
88    in
89    rec {
90      pname = "zed-editor";
91      version =
92        zedCargoLock.package.version
93        + "-nightly"
94        + lib.optionalString (commitSha != null) "+${builtins.substring 0 7 commitSha}";
95      src = builtins.path {
96        path = ../.;
97        filter = mkIncludeFilter ../.;
98        name = "source";
99      };
100
101      cargoLock = ../Cargo.lock;
102
103      nativeBuildInputs = [
104        cmake
105        copyDesktopItems
106        curl
107        perl
108        pkg-config
109        protobuf
110        # Pin cargo-about to 0.8.2. Newer versions don't work with the current license identifiers
111        # See https://github.com/zed-industries/zed/pull/44012
112        (cargo-about.overrideAttrs (
113          new: old: rec {
114            version = "0.8.2";
115
116            src = fetchFromGitHub {
117              owner = "EmbarkStudios";
118              repo = "cargo-about";
119              tag = version;
120              sha256 = "sha256-cNKZpDlfqEXeOE5lmu79AcKOawkPpk4PQCsBzNtIEbs=";
121            };
122
123            cargoHash = "sha256-NnocSs6UkuF/mCM3lIdFk+r51Iz2bHuYzMT/gEbT/nk=";
124
125            # NOTE: can drop once upstream uses `finalAttrs` here:
126            # https://github.com/NixOS/nixpkgs/blob/10214747f5e6e7cb5b9bdf9e018a3c7b3032f5af/pkgs/build-support/rust/build-rust-package/default.nix#L104
127            #
128            # See (for context): https://github.com/NixOS/nixpkgs/pull/382550
129            cargoDeps = rustPlatform.fetchCargoVendor {
130              inherit (new) src;
131              hash = new.cargoHash;
132              patches = new.cargoPatches or [ ];
133              name = new.cargoDepsName or new.finalPackage.name;
134            };
135          }
136        ))
137        rustPlatform.bindgenHook
138      ]
139      ++ lib.optionals stdenv'.hostPlatform.isLinux [ makeWrapper ]
140      ++ lib.optionals stdenv'.hostPlatform.isDarwin [
141        # Provides `ld64.lld` for clang's `-fuse-ld=lld`.
142        lld
143        (cargo-bundle.overrideAttrs (
144          new: old: {
145            version = "0.6.1-zed";
146            src = fetchFromGitHub {
147              owner = "zed-industries";
148              repo = "cargo-bundle";
149              rev = "2be2669972dff3ddd4daf89a2cb29d2d06cad7c7";
150              hash = "sha256-cSvW0ND148AGdIGWg/ku0yIacVgW+9f1Nsi+kAQxVrI=";
151            };
152            cargoHash = "sha256-urn+A3yuw2uAO4HGmvQnKvWtHqvG9KHxNCCWTiytE4k=";
153
154            # NOTE: can drop once upstream uses `finalAttrs` here:
155            # https://github.com/NixOS/nixpkgs/blob/10214747f5e6e7cb5b9bdf9e018a3c7b3032f5af/pkgs/build-support/rust/build-rust-package/default.nix#L104
156            #
157            # See (for context): https://github.com/NixOS/nixpkgs/pull/382550
158            cargoDeps = rustPlatform.fetchCargoVendor {
159              inherit (new) src;
160              hash = new.cargoHash;
161              patches = new.cargoPatches or [ ];
162              name = new.cargoDepsName or new.finalPackage.name;
163            };
164          }
165        ))
166      ];
167
168      buildInputs = [
169        curl
170        fontconfig
171        freetype
172        # TODO: need staticlib of this for linking the musl remote server.
173        # should make it a separate derivation/flake output
174        # see https://crane.dev/examples/cross-musl.html
175        libgit2
176        openssl
177        sqlite
178        zlib
179        zstd
180      ]
181      ++ lib.optionals stdenv'.hostPlatform.isLinux [
182        alsa-lib
183        glib
184        libva
185        libxkbcommon
186        wayland
187        gpu-lib
188        libglvnd
189        libx11
190        libxcb
191        libdrm
192        libgbm
193        libva
194        libxcomposite
195        libxdamage
196        libxext
197        libxfixes
198        libxrandr
199      ]
200      ++ lib.optionals stdenv'.hostPlatform.isDarwin [
201        apple-sdk_15
202        (darwinMinVersionHook "10.15")
203      ];
204
205      cargoExtraArgs = "-p zed -p cli --locked --features=gpui_platform/runtime_shaders";
206
207      stdenv =
208        pkgs:
209        let
210          base = pkgs.llvmPackages.stdenv;
211          addBinTools = old: {
212            cc = old.cc.override {
213              inherit (pkgs.llvmPackages) bintools;
214            };
215          };
216          custom = lib.pipe base [
217            (stdenv: stdenv.override addBinTools)
218            pkgs.stdenvAdapters.useMoldLinker
219          ];
220        in
221        if stdenv'.hostPlatform.isLinux then custom else base;
222
223      env = {
224        ZSTD_SYS_USE_PKG_CONFIG = true;
225        FONTCONFIG_FILE = makeFontsConf {
226          fontDirectories = [
227            ../assets/fonts/lilex
228            ../assets/fonts/ibm-plex-sans
229          ];
230        };
231        ZED_UPDATE_EXPLANATION = "Zed has been installed using Nix. Auto-updates have thus been disabled.";
232        RELEASE_VERSION = version;
233        ZED_COMMIT_SHA = lib.optionalString (commitSha != null) "${commitSha}";
234        LK_CUSTOM_WEBRTC = pkgs.callPackage ./livekit-libwebrtc/package.nix { };
235        PROTOC = "${protobuf}/bin/protoc";
236
237        CARGO_PROFILE = profile;
238        # need to handle some profiles specially https://github.com/rust-lang/cargo/issues/11053
239        TARGET_DIR = "target/" + (if profile == "dev" then "debug" else profile);
240
241        # for some reason these deps being in buildInputs isn't enough, the only thing
242        # about them that's special is that they're manually dlopened at runtime
243        NIX_LDFLAGS = lib.optionalString stdenv'.hostPlatform.isLinux "-rpath ${
244          lib.makeLibraryPath [
245            gpu-lib
246            wayland
247            libva
248          ]
249        }";
250
251        NIX_OUTPATH_USED_AS_RANDOM_SEED = "norebuilds";
252      }
253      // lib.optionalAttrs stdenv'.hostPlatform.isDarwin {
254        # Link with lld on Darwin. nixpkgs' classic open-source ld64 fails to insert
255        # ARM64 branch thunks for this binary, producing `b(l) ARM64 branch out of range`.
256        NIX_CFLAGS_LINK = "-fuse-ld=lld";
257      };
258
259      # prevent nix from removing the "unused" wayland/gpu-lib rpaths
260      dontPatchELF = stdenv'.hostPlatform.isLinux;
261
262      # TODO: try craneLib.cargoNextest separate output
263      # for now we're not worried about running our test suite (or tests for deps) in the nix sandbox
264      doCheck = false;
265
266      cargoVendorDir = craneLib.vendorCargoDeps {
267        inherit src cargoLock;
268        overrideVendorGitCheckout =
269          let
270            hasWebRtcSys = builtins.any (crate: crate.name == "webrtc-sys");
271            # we can't set $RUSTFLAGS because that clobbers the cargo config
272            # see https://github.com/rust-lang/cargo/issues/5376#issuecomment-2163350032
273            glesConfig = builtins.toFile "config.toml" ''
274              [target.'cfg(all())']
275              rustflags = ["--cfg", "gles"]
276            '';
277
278            # `webrtc-sys` expects a staticlib; nixpkgs' `livekit-webrtc` has been patched to
279            # produce a `dylib`... patching `webrtc-sys`'s build script is the easier option
280            # TODO: send livekit sdk a PR to make this configurable
281            postPatch = ''
282              substituteInPlace webrtc-sys/build.rs --replace-fail \
283                "cargo:rustc-link-lib=static=webrtc" "cargo:rustc-link-lib=dylib=webrtc"
284
285              substituteInPlace webrtc-sys/build.rs --replace-fail \
286                'add_gio_headers(&mut builder);' \
287                'for lib_name in ["glib-2.0", "gio-2.0"] {
288                    if let Ok(lib) = pkg_config::Config::new().cargo_metadata(false).probe(lib_name) {
289                        for path in lib.include_paths {
290                            builder.include(&path);
291                        }
292                    }
293                }'
294            ''
295            + lib.optionalString withGLES ''
296              cat ${glesConfig} >> .cargo/config/config.toml
297            '';
298          in
299          crates: drv:
300          if hasWebRtcSys crates then
301            drv.overrideAttrs (o: {
302              postPatch = (o.postPatch or "") + postPatch;
303            })
304          else
305            drv;
306      };
307    };
308  cargoArtifacts = craneLib.buildDepsOnly commonArgs;
309in
310craneLib.buildPackage (
311  lib.recursiveUpdate commonArgs {
312    inherit cargoArtifacts;
313
314    # Expose the crane builder and shared arguments so other derivations (e.g.
315    # the docs preprocessor in the devshell) can build sibling workspace crates
316    # without duplicating all of the build inputs and environment setup.
317    passthru = {
318      inherit craneLib commonArgs cargoArtifacts;
319    };
320
321    dontUseCmakeConfigure = true;
322
323    # without the env var generate-licenses fails due to crane's fetchCargoVendor, see:
324    # https://github.com/zed-industries/zed/issues/19971#issuecomment-2688455390
325    # TODO: put this in a separate derivation that depends on src to avoid running it on every build
326    preBuild = ''
327      ALLOW_MISSING_LICENSES=yes bash script/generate-licenses
328      echo nightly > crates/zed/RELEASE_CHANNEL
329    '';
330
331    installPhase =
332      if stdenv.hostPlatform.isDarwin then
333        ''
334          runHook preInstall
335
336          pushd crates/zed
337          sed -i "s/package.metadata.bundle-nightly/package.metadata.bundle/" Cargo.toml
338          export CARGO_BUNDLE_SKIP_BUILD=true
339          app_path="$(cargo bundle --profile $CARGO_PROFILE | xargs)"
340          popd
341
342          mkdir -p $out/Applications $out/bin
343          # Zed expects git next to its own binary
344          ln -s ${git}/bin/git "$app_path/Contents/MacOS/git"
345          mv $TARGET_DIR/cli "$app_path/Contents/MacOS/cli"
346          mv "$app_path" $out/Applications/
347
348          # Physical location of the CLI must be inside the app bundle as this is used
349          # to determine which app to start
350          ln -s "$out/Applications/Zed Nightly.app/Contents/MacOS/cli" $out/bin/zed
351
352          runHook postInstall
353        ''
354      else
355        ''
356          runHook preInstall
357
358          mkdir -p $out/bin $out/libexec
359          cp $TARGET_DIR/zed $out/libexec/zed-editor
360          cp $TARGET_DIR/cli  $out/bin/zed
361          ln -s $out/bin/zed $out/bin/zeditor  # home-manager expects the CLI binary to be here
362
363
364          install -D "crates/zed/resources/app-icon-nightly@2x.png" \
365            "$out/share/icons/hicolor/1024x1024@2x/apps/zed.png"
366          install -D crates/zed/resources/app-icon-nightly.png \
367            $out/share/icons/hicolor/512x512/apps/zed.png
368
369          # TODO: icons should probably be named "zed-nightly"
370          (
371            export DO_STARTUP_NOTIFY="true"
372            export APP_CLI="zed"
373            export APP_ICON="zed"
374            export APP_NAME="Zed Nightly"
375            export APP_ARGS="%U"
376            mkdir -p "$out/share/applications"
377            ${lib.getExe envsubst} < "crates/zed/resources/zed.desktop.in" > "$out/share/applications/dev.zed.Zed-Nightly.desktop"
378            chmod +x "$out/share/applications/dev.zed.Zed-Nightly.desktop"
379          )
380
381          runHook postInstall
382        '';
383
384    # TODO: why isn't this also done on macOS?
385    postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
386      wrapProgram $out/libexec/zed-editor --suffix PATH : ${lib.makeBinPath [ nodejs_22 ]}
387    '';
388
389    meta = {
390      description = "High-performance, multiplayer code editor from the creators of Atom and Tree-sitter";
391      homepage = "https://zed.dev";
392      changelog = "https://zed.dev/releases/preview";
393      license = lib.licenses.gpl3Only;
394      mainProgram = "zed";
395      platforms = lib.platforms.linux ++ lib.platforms.darwin;
396    };
397  }
398)
399
Served at tenant.openagents/omega Member data and write actions are omitted.