dev-templates/rust/flake.nix

48 lines
1.4 KiB
Nix
Raw Normal View History

2022-07-16 16:48:23 +02:00
{
description = "A Nix-flake-based Rust development environment";
inputs = {
2022-08-20 12:06:53 +02:00
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs";
2022-07-16 16:48:23 +02:00
rust-overlay.url = "github:oxalica/rust-overlay";
};
2022-08-20 12:06:53 +02:00
outputs = { self, flake-utils, nixpkgs, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
2022-07-16 16:48:23 +02:00
let
2022-07-29 00:11:05 +02:00
overlays = [ (import rust-overlay) ];
2022-07-16 16:48:23 +02:00
2022-07-29 00:11:05 +02:00
pkgs = import nixpkgs { inherit system overlays; };
2022-07-31 16:47:47 +02:00
inherit (pkgs) mkShell rust-bin;
inherit (pkgs.lib) optionals;
inherit (pkgs.stdenv) isLinux;
2022-07-16 16:48:23 +02:00
2022-08-20 13:47:43 +02:00
rust =
if builtins.pathExists ./rust-toolchain.toml then
rust-bin.fromRustupToolchainFile ./rust-toolchain.toml
else if builtins.pathExists ./rust-toolchain then
rust-bin.fromRustupToolchainFile ./rust-toolchain
else
rust-bin.stable.latest.default;
2022-07-16 16:48:23 +02:00
2022-07-31 16:47:47 +02:00
deps = with pkgs; [ openssl pkgconfig ];
rustTools = with pkgs;
2022-07-31 23:03:09 +02:00
[ cargo-audit cargo-deny cargo-cross rust-analyzer ]
++ optionals isLinux (with pkgs; [ cargo-watch ]);
2022-08-20 13:47:43 +02:00
in
{
2022-07-16 16:48:23 +02:00
packages.default = rust;
devShells = {
2022-07-28 23:20:46 +02:00
default = mkShell {
2022-07-31 16:47:47 +02:00
nativeBuildInputs = [ rust ] ++ deps ++ rustTools;
2022-07-16 16:48:23 +02:00
shellHook = ''
2022-07-28 23:42:40 +02:00
${rust}/bin/cargo --version
2022-07-16 16:48:23 +02:00
'';
};
};
2022-07-29 00:11:05 +02:00
});
2022-07-16 16:48:23 +02:00
}