dotfiles/templates/rust/flake.nix

60 lines
1.9 KiB
Nix
Raw Normal View History

2024-01-20 13:08:31 +01:00
{
inputs = {
2024-01-21 14:53:56 +01:00
crane.url = "github:ipetkov/crane";
crane.inputs.nixpkgs.follows = "nixpkgs";
fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
2024-01-20 13:08:31 +01:00
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "nixpkgs/nixos-unstable";
};
2024-01-21 14:53:56 +01:00
outputs = { self, crane, flake-utils, nixpkgs, ... }@inputs:
2024-01-20 13:08:31 +01:00
flake-utils.lib.eachDefaultSystem (system:
let
2024-01-21 14:53:56 +01:00
inherit (pkgs) lib;
pkgs = import nixpkgs { inherit system; };
fenix = inputs.fenix.packages.${system};
2024-01-20 13:08:31 +01:00
craneLib = crane.lib.${system}.overrideToolchain toolchain.toolchain;
2024-01-21 14:53:56 +01:00
mkSrc = extraPaths: with lib.fileset; let
root = ./.;
rustFiles = fromSource (craneLib.cleanCargoSource root);
fileset = union rustFiles (unions extraPaths);
in
toSource { inherit root fileset; };
## Customize here ##
toolchain = fenix.complete; # or fenix.stable;
2024-01-20 16:24:08 +01:00
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv;
2024-01-20 13:08:31 +01:00
in
{
2024-01-21 14:53:56 +01:00
packages.default = craneLib.buildPackage {
inherit stdenv;
src = mkSrc [ ];
strictDeps = true;
buildInputs = [
# Add additional build inputs here
] ++ lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
# Additional environment variables can be set directly
# MY_CUSTOM_VAR = "some value";
};
2024-01-20 13:08:31 +01:00
2024-01-21 14:53:56 +01:00
devShells.default = pkgs.mkShell.override { inherit stdenv; }
2024-01-20 13:08:31 +01:00
{
2024-01-21 14:53:56 +01:00
nativeBuildInputs = with pkgs; [
# Add additional build inputs here
] ++ (with toolchain; [
cargo
clippy
rustfmt
rustc
fenix.rust-analyzer
]);
RUST_SRC_PATH = "${toolchain.rust-src}/lib/rustlib/src/rust/library";
2024-01-20 13:08:31 +01:00
};
2024-01-21 14:53:56 +01:00
}
);
2024-01-20 13:08:31 +01:00
}