94 lines
2.5 KiB
Nix
94 lines
2.5 KiB
Nix
{
|
|
description = "A Rust project template using Nix flakes (rust-overlay, naersk, flake-utils)";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
rust-overlay.url = "github:oxalica/rust-overlay";
|
|
naersk.url = "github:nix-community/naersk";
|
|
};
|
|
|
|
outputs = inputs@{ self, nixpkgs, flake-utils, rust-overlay, naersk, ... }:
|
|
flake-utils.lib.eachSystem flake-utils.lib.allSystems (system:
|
|
let
|
|
projectName = "rust-template";
|
|
projectVersion = "0.1.0";
|
|
rustVersion = "1.78.0";
|
|
|
|
pkgs = import nixpkgs {
|
|
inherit system;
|
|
overlays = [ (import rust-overlay) ];
|
|
};
|
|
|
|
rustToolchain = pkgs.rust-bin.fromRustVersion {
|
|
rustVersion = rustVersion;
|
|
extensions = [ "rust-src" "rustfmt" "clippy" ];
|
|
};
|
|
|
|
rustLibSrc = "${rustToolchain}/lib/rustlib/src/rust";
|
|
|
|
commonBuildInputs = with pkgs; [
|
|
glib
|
|
];
|
|
|
|
commonNativeBuildInputs = with pkgs; [
|
|
pkg-config
|
|
];
|
|
|
|
devPackages = with pkgs; [
|
|
# Rust-specific tools
|
|
rust-analyzer
|
|
sccache
|
|
cargo-watch
|
|
|
|
# General developer experience
|
|
just
|
|
nil
|
|
alejandra
|
|
direnv
|
|
nix-direnv
|
|
] ++ commonNativeBuildInputs ++ commonBuildInputs;
|
|
|
|
myRustProject = naersk.lib."${system}".buildPackage {
|
|
inherit (self) src;
|
|
rustToolchain = rustToolchain;
|
|
pname = projectName;
|
|
version = projectVersion;
|
|
nativeBuildInputs = commonNativeBuildInputs;
|
|
buildInputs = commonBuildInputs;
|
|
cargoLock = {
|
|
lockFile = ./Cargo.lock;
|
|
};
|
|
};
|
|
|
|
in
|
|
{
|
|
packages.default = myRustProject;
|
|
|
|
packages.rustToolchain = rustToolchain;
|
|
|
|
devShells.default = pkgs.mkShell {
|
|
name = "${projectName}-dev-shell";
|
|
|
|
inputsFrom = [ rustToolchain ];
|
|
|
|
RUST_SRC_PATH = rustLibSrc;
|
|
RUSTC_WRAPPER = "${pkgs.sccache}/bin/sccache";
|
|
SCCACHE_DIR = "$HOME/.cache/sccache";
|
|
|
|
packages = devPackages;
|
|
|
|
shellHook = ''
|
|
echo "Welcome to the Rust development shell!"
|
|
echo "Current Rust version: $(rustc --version)"
|
|
echo "Current Cargo version: $(cargo --version)"
|
|
'';
|
|
};
|
|
|
|
apps.default = flake-utils.lib.mkApp {
|
|
drv = myRustProject;
|
|
};
|
|
|
|
checks.build = myRustProject;
|
|
});
|
|
} |