cargo new rust-static-nix
cd rust-static-nix
cargo build
# create/copy default.nix
nix-build
Created
February 9, 2020 10:26
-
-
Save thalesmg/fb04f91e789db460485db33c795d8c7c to your computer and use it in GitHub Desktop.
How to statically compile a Rust binary using MUSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
base-nixpkgs = import <nixpkgs> {}; | |
mozillaOverlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz); | |
nixpkgs = import <nixpkgs> { overlays = [ mozillaOverlay ]; }; | |
rust = (nixpkgs.rustChannelOf { channel = "stable"; }).rust.override { | |
targets = [ "x86_64-unknown-linux-musl" ]; | |
}; | |
rustPlatform = nixpkgs.makeRustPlatform { | |
cargo = rust; | |
rustc = rust; | |
}; | |
in | |
rustPlatform.buildRustPackage { | |
name = "rust-static-nix"; | |
src = ./.; | |
cargoSha256 = "0jacm96l1gw9nxwavqi1x4669cg6lzy9hr18zjpwlcyb3qkw9z7f"; | |
target = "x86_64-unknown-linux-musl"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment