Skip to content

Commit

Permalink
feat: migrate the dev shell to musl
Browse files Browse the repository at this point in the history
  • Loading branch information
louib committed Aug 17, 2024
1 parent 6b9bb0e commit aee4e31
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 7 deletions.
60 changes: 60 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 31 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,35 @@ rec {
flake-utils = {
url = "github:numtide/flake-utils";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = {
self,
nixpkgs,
flake-utils,
fenix,
naersk,
}: (
flake-utils.lib.eachDefaultSystem (
flake-utils.lib.eachSystem [
# Right now this has only been tested on one system.
"x86_64-linux"
]
(
system: (
let
authorName = "louib";
mainBranch = "main";
authorEmail = "[email protected]";
projectName = "nix2sbom";
targetSystem = "x86_64-unknown-linux-musl";

pkgs = import nixpkgs {
inherit system;
Expand All @@ -32,16 +47,25 @@ rec {
rustc
rustfmt
];

# Defining our fenix-based Rust toolchain.
fenixPkgs = fenix.packages.${system};
toolchain = fenixPkgs.combine [
fenixPkgs.minimal.cargo
fenixPkgs.minimal.rustc
fenixPkgs.targets.${targetSystem}.latest.rust-std
];

crossPkgs = naersk.lib.${system}.override {
cargo = toolchain;
rustc = toolchain;
};
in {
devShells = {
default = pkgs.mkShell {
# nativeBuildInputs = cargoPackages ++ [pkgs.glibc.static pkgs.pkg-config];
buildInputs = cargoPackages;

buildInputs = [toolchain];
shellHook = ''
# Even with that flag, the target has to be passed explicitly when building:
# cargo build --release --target x86_64-unknown-linux-gnu
# export RUSTFLAGS='-C target-feature=+crt-static'
export CARGO_BUILD_TARGET="${targetSystem}"
'';
};
};
Expand Down

0 comments on commit aee4e31

Please sign in to comment.