Skip to content

Instantly share code, notes, and snippets.

@e-nomem
Created November 9, 2022 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e-nomem/3d47b0d7aab28d0b47c5247ea95ec999 to your computer and use it in GitHub Desktop.
Save e-nomem/3d47b0d7aab28d0b47c5247ea95ec999 to your computer and use it in GitHub Desktop.
Rust Nix Flake Setup
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
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 (system: let
pkgs = nixpkgs.legacyPackages.${system};
rust-toolchain = fenix.packages.${system}.toolchainOf {
channel = "1.62.1";
# sha256 = pkgs.lib.fakeSha256;
sha256 = "sha256-Et8XFyXhlf5OyVqJkxrmkxv44NRN54uU2CLUTZKUjtM=";
};
in rec {
# Build the crate and bin
packages.default = (naersk.lib.${system}.override {
inherit (rust-toolchain) cargo rustc;
}).buildPackage { src = ./.; };
# Run the bin
apps.default = flake-utils.lib.mkApp {
drv = packages.default;
exePath = "/bin/main";
};
# For use with `nix develop`
devShells.default = pkgs.mkShell {
nativeBuildInputs = [
(rust-toolchain.withComponents [
"cargo"
"clippy"
"rustc"
"rustfmt"
"rust-src"
])
];
};
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment