dev-templates/rust/flake.nix

46 lines
1.2 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-29 02:29:34 +02:00
inherit (pkgs) rust-bin;
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-29 02:29:34 +02:00
helpers = with pkgs; [ openssl pkgconfig ];
2022-07-28 23:42:40 +02:00
2022-07-28 23:20:46 +02:00
inherit (pkgs) mkShell;
2022-07-16 16:48:23 +02:00
inherit (pkgs.lib) optionals;
inherit (pkgs.stdenv) isDarwin;
in {
packages.default = rust;
devShells = {
2022-07-28 23:20:46 +02:00
default = mkShell {
2022-07-29 02:29:34 +02:00
nativeBuildInputs = [ rust ];
buildInputs = helpers;
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
}