Rust cross-platform

Hello,
I am attempting to build a thing that requires me to build for a Windows target, and I’m very much at a loss as to how to do this.
I’ve seen some questions floating around here, but none of them have been very useful to me (read: I didn’t understand what to do / couldn’t get it to work the way I wanted)

Ideally, what I want is a flake.nix that provides me with Cargo configured in a way that when I run cargo build (or maybe cargo build --target x86_64-pc-windows-gnu or whatever), it builds my project for Windows.
The first thing I tried was just adapting the shell.nix mentioned on the wiki to a flake.nix - without much success; I get derivation build errors that make it look like it’s somehow mixing up the build / target architecture.
I have found a few things that use the Nix flake build system (flakebox, naersk), but I didn’t go much further with these for the following reason: there may be other ppl working on the project, and I don’t want to force them to deal with flakes, because I can barely deal with them myself; I only use them because of the nice direnv integration, and the per-project package management and version-locking that this allows.

So can anyone tell me how to cross-compile Rust for Windows on NixOS? Or point out the part where I’m doing things fundamentally wrong that is making it difficult to do things correctly?

I think you want the equivalent of pkgsCross.mingwW64.ripgrep (with your package instead of ripgrep).

I recently did that in wastebin/flake.nix at a9690dc26cbfd741e11e396d66954c6bd287adb2 · FliegendeWurst/wastebin · GitHub. It is a bit messy but it works. Look for x86_64-linux-cross-aarch64-linux, and mentions of "-cross-". (You also need to change aarch64-linux to your Windows target.)

There is a good chance my solution is not the most elegant.

EDIT: my solution would not work if you need a dev shell. I would try plain rustup in that case.

Thanks, I’ll take a look at this.