Created
November 9, 2022 15:58
-
-
Save e-nomem/3d47b0d7aab28d0b47c5247ea95ec999 to your computer and use it in GitHub Desktop.
Rust Nix Flake Setup
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
{ | |
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