dev-templates/rust/flake.nix

45 lines
1.3 KiB
Nix
Raw Normal View History

2022-07-16 16:48:23 +02:00
{
description = "A Nix-flake-based Rust development environment";
inputs = {
2022-07-31 12:57:49 +02:00
dev.url = "github:the-nix-way/dev-templates";
2022-07-16 16:48:23 +02:00
rust-overlay.url = "github:oxalica/rust-overlay";
};
2022-07-31 12:57:49 +02:00
outputs = { self, dev, rust-overlay }:
2022-07-31 13:02:06 +02:00
let inherit (dev.lib) flake-utils nixpkgs;
2022-07-31 12:57:49 +02:00
in 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-07-29 02:29:34 +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 17:59:22 +02:00
[ rust-analyzer ] ++ optionals isLinux (with pkgs; [ cargo-watch ]);
2022-07-16 16:48:23 +02:00
in {
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
}