1{2 lib,3 pkgs,4 stdenv,5 callPackage,6 fetchurl,7 pkg-config,8 rustPlatform,9 rustc,10 rofi,11 installShellFiles,12 inputs,13 remowt-agents-bundle,14 rustToolchain ? null,15}:16let17 system = stdenv.hostPlatform.system;18 nocargoSrc = inputs.nocargo;19 nocargoLib = import (nocargoSrc + "/lib") {20 inherit lib;21 inherit (inputs.nocargo.inputs) nix-filter;22 };23 toml2json = callPackage (nocargoSrc + "/toml2json") { };24 buildRustCrateUnwrapped = callPackage (nocargoSrc + "/build-rust-crate") {25 nocargo-lib = nocargoLib;26 inherit toml2json;27 };28 29 30 31 buildRustCrate =32 args:33 let34 profile = args.profile or { };35 crate = buildRustCrateUnwrapped (36 args37 // {38 profile = removeAttrs profile [ "panic" ];39 buildFlags = [ "--cfg=tokio_unstable" ] ++ args.buildFlags or [ ];40 41 42 43 44 45 postHook = ''46 _newLdflags=47 for _flag in $NIX_LDFLAGS; do48 if [[ "$_flag" == -L/nix/store/*-rust_*/lib ]]; then continue; fi49 _newLdflags+="''${_newLdflags:+ }$_flag"50 done51 export NIX_LDFLAGS="$_newLdflags"52 unset _newLdflags _flag53 '';54 }55 );56 in57 if profile.panic or "unwind" == "unwind" then58 crate59 else60 crate61 // {62 bin = crate.bin.overrideAttrs (old: {63 buildFlags = old.buildFlags ++ [ "-Cpanic=${profile.panic}" ];64 });65 };6667 extraProcMacroCrates = [68 "bifrostlink-macros"69 "curve25519-dalek-derive"70 "derive_more-impl"71 "iroh-metrics-derive"72 "jni-macros"73 "jni-sys-macros"74 "n0-error-macros"75 "proc-macro-error-attr2"76 "prost-derive"77 "spez"78 "test-log-macros"79 ];80 cratesIoOverride =81 import (nocargoSrc + "/crates-io-override") { inherit lib pkgs; }82 // lib.genAttrs extraProcMacroCrates (_: _: { procMacro = true; })83 // {84 derive_more = { version, ... }: { procMacro = lib.versionOlder version "1.0.0"; };85 test-log = { version, ... }: { procMacro = lib.versionOlder version "0.2.12"; };86 87 88 89 90 scratch = _: {91 postConfigure = ''92 export OUT_DIR="$NIX_BUILD_TOP/rust-scratch-out-dir"93 mkdir -p "$OUT_DIR"94 '';95 };96 };97 cratesIoIndex = nocargoLib.pkg-info.mkIndex fetchurl inputs.registry-crates-io cratesIoOverride;9899 mkRustPackageOrWorkspace = callPackage nocargoLib.support.mkRustPackageOrWorkspace {100 defaultRegistries = {101 "https://github.com/rust-lang/crates.io-index" = cratesIoIndex;102 };103 inherit buildRustCrate;104 };105106 ws = mkRustPackageOrWorkspace {107 src = lib.cleanSourceWith {108 src = ../.;109 filter =110 path: type:111 (if type == "directory" then baseNameOf path != "target" else true)112 && (113 type == "directory"114 || lib.any (suffix: lib.hasSuffix suffix path) [115 ".rs"116 ".toml"117 ".cc"118 ".hh"119 ]120 || baseNameOf path == "Cargo.lock"121 );122 };123 rustc = if rustToolchain != null then rustToolchain else rustc;124 buildCrateOverrides = {125 nix-eval = _: {126 nativeBuildInputs = [127 pkg-config128 rustPlatform.bindgenHook129 ];130 propagatedBuildInputs = [131 inputs.nix.packages.${system}.nix-expr-c132 inputs.nix.packages.${system}.nix-flake-c133 inputs.nix.packages.${system}.nix-fetchers-c134 ];135 };136 fleet-base = _: {137 REMOWT_AGENTS_DIR = "${remowt-agents-bundle}";138 };139 remowt-ui-prompt = _: {140 ROFI = "${rofi}/bin/rofi";141 };142 };143 };144145 fleet = ws.release.fleet.bin;146in147stdenv.mkDerivation {148 pname = "fleet-nocargo";149 inherit (fleet) version;150151 nativeBuildInputs = [ installShellFiles ];152153 buildCommand = ''154 mkdir -p $out/bin155 ln -s ${fleet}/bin/* $out/bin/156157 for shell in bash fish zsh; do158 installShellCompletion --cmd fleet \159 --$shell <($out/bin/fleet complete --shell $shell)160 done161 '';162163 passthru.workspace = ws;164}