Skip to content

Instantly share code, notes, and snippets.

@MatthewCash
Created July 11, 2025 02:40
Show Gist options
  • Select an option

  • Save MatthewCash/637240d6ffe156562fd42d49b226b24b to your computer and use it in GitHub Desktop.

Select an option

Save MatthewCash/637240d6ffe156562fd42d49b226b24b to your computer and use it in GitHub Desktop.
nix flake for rust + musl
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { nixpkgs, rust-overlay, ... }:
let
forAllSystems = f: nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed f;
in {
devShells = forAllSystems (system: {
default = nixpkgs.legacyPackages.${system}.mkShell (
let
pkgs = import nixpkgs {
localSystem = system;
overlays = [ rust-overlay.overlays.rust-overlay ];
};
cc = pkgs.lib.getExe pkgs.pkgsStatic.stdenv.cc;
in {
packages = [
(pkgs.rust-bin.stable.latest.default.override {
targets = [ "x86_64-unknown-linux-musl" ];
})
];
env = {
CC_x86_64_unknown_linux_musl = cc;
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER = cc;
};
});
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment