{ description = "polymodel: AT Protocol-native model/project sharing app built with Rust/Dioxus/Jacquard"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; rust-overlay.url = "github:oxalica/rust-overlay"; # Use nixpkgs dioxus-cli; do not import the upstream Dioxus flake because it may be ahead of Cargo.toml. }; outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; overlays = [ (import rust-overlay) ]; }; rustToolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override { targets = ["wasm32-unknown-unknown"]; extensions = [ "rust-src" "rust-analyzer" "clippy" "rustfmt" ]; }); ldparseRev = "0fe78dcee22982f26cceced1b483340faa4d04e9"; immerRev = "141af37e46a75fce48318b13bf2bf71f51950de8"; coroutinesRev = "a26a43912319fd2c40823dc96755990da765bc8f"; ldparse = pkgs.fetchFromGitHub { owner = "elfprince13"; repo = "LDParse"; rev = ldparseRev; sha256 = "04frdxpb6kvrzggvbfq66cb95w7g6lf7yzyqaw3qyqvsnqbyw7r0"; }; immerSrc = pkgs.fetchFromGitHub { owner = "arximboldi"; repo = "immer"; rev = immerRev; sha256 = "10drhxqgr6pp4bih9kbcdk0x39gdz8r85zryfydisqq7gwp4ibfz"; }; coroutinesSrc = pkgs.fetchFromGitHub { owner = "Geopipe"; repo = "CxxBidirectionalCoroutines"; rev = coroutinesRev; sha256 = "10bdz6l5i1qgniysgm7fmrds76yh9kj59wfv7zk9kzvj76qqkdpq"; }; ldrawParts = pkgs.stdenv.mkDerivation { pname = "ldraw-parts"; version = "2026-06"; src = pkgs.fetchurl { url = "https://library.ldraw.org/library/updates/complete.zip"; sha256 = "sha256-YAny6UIExNOmOkyBIBC1yQutjFrLGbiCyFn9rGNzTq4="; }; nativeBuildInputs = [ pkgs.unzip ]; unpackPhase = "unzip $src"; installPhase = '' runHook preInstall mkdir -p $out cp -r ldraw/* $out/ runHook postInstall ''; }; ldrawOracle = pkgs.stdenv.mkDerivation { pname = "ldraw-oracle"; version = ldparseRev; src = ldparse; nativeBuildInputs = [ pkgs.cmake pkgs.pkg-config pkgs.makeWrapper ]; buildInputs = [ pkgs.boost pkgs.glm pkgs.fmt ]; patches = [ ./patches/ldparse-oracle-access.patch ./patches/ldparse-geometry-accumulation.patch ]; cmakeFlags = [ "-DCMAKE_POLICY_VERSION_MINIMUM=3.5" ]; postPatch = '' test "${ldparseRev}" = "0fe78dcee22982f26cceced1b483340faa4d04e9" # Place separately-fetched submodules into deps/ rm -rf deps/immer deps/CxxBidirectionalCoroutines cp -r ${immerSrc} deps/immer cp -r ${coroutinesSrc} deps/CxxBidirectionalCoroutines # Disable face-unwrapper (not needed for oracle) and fix case mismatch: # GitHub archive has ParseTest/ but CMakeLists references lowercase parsetest sed -i '/add_subdirectory(face-unwrapper)/d' CMakeLists.txt sed -i '/add_subdirectory(parsetest)/d' CMakeLists.txt # GCC 15 requires explicit include for std::unique_ptr in Cache.hpp sed -i '1i #include ' include/LDParse/Cache.hpp # GCC 15 requires explicit lambda capture for offset in Geom.hpp sed -i 's/\[\](uint32_t &index){ index += offset; }/[offset](uint32_t \&index){ index += offset; }/' include/LDParse/Geom.hpp # Callbacks can be invoked after an MPD NOFILE retargets them to nullptr. # Ignore those stale parser events instead of asserting in the oracle. sed -i 's/assert((mTarget != nullptr) \&\& "Invalid target");/if(!mTarget) return R();/' include/LDParse/ModelBuilder/ModelBuilderDefs.hpp cp ${./tools/ldraw-oracle/oracle.cpp} oracle.cpp ''; buildPhase = '' runHook preBuild cmake --build . --parallel "$NIX_BUILD_CORES" ldparse_lib=$(find . -type f -name 'libLDParse.so*' -print -quit) test -n "$ldparse_lib" ldparse_lib_dir=$(dirname "$ldparse_lib") c++ -std=c++17 -I../include -I../deps/immer -I../deps/CxxBidirectionalCoroutines/include -I${pkgs.boost.dev}/include -I${pkgs.glm}/include -I${pkgs.fmt.dev}/include ${./tools/ldraw-oracle/oracle.cpp} -L"$ldparse_lib_dir" -Wl,-rpath,"\$$ORIGIN/../lib" -lLDParse -lboost_filesystem -o ldraw-oracle runHook postBuild ''; installPhase = '' runHook preInstall ldparse_lib=$(find . -type f -name 'libLDParse.so*' -print -quit) test -n "$ldparse_lib" install -Dm755 "$ldparse_lib" "$out/lib/$(basename "$ldparse_lib")" install -Dm755 ldraw-oracle $out/bin/ldraw-oracle install -Dm644 ${./tools/ldraw-oracle/oracle.cpp} $out/share/ldraw-oracle/oracle.cpp install -Dm644 ${./patches/ldparse-oracle-access.patch} $out/share/ldraw-oracle/ldparse-oracle-access.patch cat > $out/share/ldraw-oracle/provenance.txt <