Skip to content

Instantly share code, notes, and snippets.

@jcaesar
Last active February 17, 2024 06:47
Show Gist options
  • Save jcaesar/672d49387de9a8275d030913c2bb23c7 to your computer and use it in GitHub Desktop.
Save jcaesar/672d49387de9a8275d030913c2bb23c7 to your computer and use it in GitHub Desktop.
rust-nix-musl-dyn
use flake
/target/
/.direnv/
/result
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "rust-musl-hello"
version = "0.1.0"
[package]
name = "rust-musl-hello"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "rust-musl-hello"
path = "main.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1708093448,
"narHash": "sha256-gohEm3/NVyu7WINFhRf83yJH8UM2ie/KY9Iw3VN6fiE=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "c7763249f02b7786b4ca36e13a4d7365cfba162f",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}
{
description = "Hello world Rust program statically linked against musl";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
outputs = { nixpkgs, ... }:
let
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
mk = localSystem: crossSystem: rec {
systems = (if localSystem == crossSystem then {
system = localSystem;
} else {
inherit crossSystem localSystem;
});
pkgs = (import nixpkgs systems).pkgsMusl;
main = pkgs.rustPlatform.buildRustPackage {
pname = "rust-musl-hello";
version = "0.1.0";
src = ./.;
cargoLock = { lockFile = ./Cargo.lock; };
};
image = pkgs.dockerTools.streamLayeredImage {
name = "rust-musl-dynamic-hello";
tag = "latest";
contents = [ pkgs.busybox main ];
config = { Cmd = [ "/bin/rust-musl-hello" ]; };
};
};
in {
packages = forAllSystems
(localSystem: { default = (mk localSystem localSystem).main; });
apps = forAllSystems (localSystem:
let
mkAI = remoteSystem: {
type = "app";
program = toString (mk localSystem remoteSystem).image;
};
in {
mkImageI = mkAI "x86_64-linux";
mkImageA = mkAI "aarch64-linux";
});
devShells = forAllSystems (system:
let pkgs = import nixpkgs { inherit system; };
in {
default = pkgs.mkShell { buildInputs = with pkgs; [ cargo nixfmt ]; };
});
};
}
fn main() {
println!("Hello, world!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment