Created
July 30, 2024 15:42
-
-
Save Yash-Garg/ada9170c39643bc9a471e1a3deee4f71 to your computer and use it in GitHub Desktop.
Nix Flake for Rust (MacOS Specific due to Linker Issues)
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
{ | |
description = "devshell for a Rust project"; | |
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; | |
inputs.devshell.url = "github:numtide/devshell"; | |
inputs.devshell.inputs.nixpkgs.follows = "nixpkgs"; | |
inputs.flake-utils.url = "github:numtide/flake-utils"; | |
inputs.flake-compat.url = "github:nix-community/flake-compat"; | |
inputs.flake-compat.flake = false; | |
inputs.fenix.url = "github:nix-community/fenix"; | |
inputs.fenix.inputs.nixpkgs.follows = "nixpkgs"; | |
inputs.crane.url = "github:ipetkov/crane"; | |
inputs.crane.inputs.nixpkgs.follows = "nixpkgs"; | |
outputs = | |
{ | |
self, | |
nixpkgs, | |
crane, | |
devshell, | |
fenix, | |
flake-utils, | |
... | |
}: | |
flake-utils.lib.eachDefaultSystem ( | |
system: | |
let | |
pkgs = import nixpkgs { | |
inherit system; | |
overlays = [ devshell.overlays.default ]; | |
}; | |
rustStable = (import fenix { inherit pkgs; }).fromToolchainFile { | |
file = ./toolchain.toml; | |
sha256 = "sha256-6eN/GKzjVSjEhGO9FhWObkRFaE1Jf+uqMSdQnb8lcB4="; | |
}; | |
craneLib = (crane.mkLib pkgs).overrideToolchain rustStable; | |
custom-package = craneLib.buildPackage { | |
src = craneLib.cleanCargoSource (craneLib.path ./.); | |
buildInputs = [ ]; | |
nativeBuildInputs = [ ]; | |
cargoClippyExtraArgs = "--all-targets -- --deny warnings"; | |
}; | |
in | |
{ | |
checks = { | |
inherit custom-package; | |
}; | |
packages.default = custom-package; | |
apps.default = flake-utils.lib.mkApp { drv = custom-package; }; | |
devShells.default = pkgs.devshell.mkShell { | |
env = [ | |
{ | |
name = "DEVSHELL_NO_MOTD"; | |
value = 1; | |
} | |
{ | |
name = "LDFLAGS"; | |
value = "-F/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/"; | |
} | |
{ | |
name = "LIBRARY_PATH"; | |
value = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/"; | |
} | |
]; | |
packages = with pkgs; [ | |
openssl | |
pkg-config | |
rustStable | |
stdenv.cc | |
]; | |
}; | |
} | |
); | |
} |
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
[toolchain] | |
channel = "stable" | |
components = [ "rustfmt", "rust-src", "clippy" ] | |
profile = "minimal" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment