rust-nix-template/flake.nix

85 lines
2.1 KiB
Nix
Raw Normal View History

2021-04-07 00:17:50 +02:00
{
2024-05-03 19:35:19 +02:00
description = "A Nix-flake-based Rust development environment";
2021-04-07 00:17:50 +02:00
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
2023-06-26 18:32:36 +02:00
2024-05-03 19:35:19 +02:00
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
2021-04-07 00:17:50 +02:00
};
2024-05-03 19:35:19 +02:00
outputs =
{
self,
nixpkgs,
treefmt-nix,
fenix,
}:
let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
2023-06-26 18:32:36 +02:00
];
2024-05-03 19:35:19 +02:00
forEachSupportedSystem =
f:
nixpkgs.lib.genAttrs supportedSystems (
system:
f (
let
pkgs = import nixpkgs { inherit system; };
fenix' = (import fenix { inherit system pkgs; });
toolchain = fenix'.complete.withComponents (
(builtins.fromTOML (builtins.readFile ./rust-toolchain.toml)).toolchain.components
);
in
{
inherit pkgs toolchain;
}
)
);
in
{
formatter = forEachSupportedSystem (
{ pkgs, ... }: (treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build.wrapper
);
devShells = forEachSupportedSystem (
{ pkgs, toolchain }:
{
2024-05-03 19:35:19 +02:00
default = pkgs.mkShell {
nativeBuildInputs = [ toolchain ];
buildInputs = [ toolchain ];
2023-07-23 16:11:14 +02:00
};
2024-05-03 19:35:19 +02:00
}
);
packages = forEachSupportedSystem (
{ pkgs, toolchain }:
{
default = (
let
manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
rustPlatform = pkgs.makeRustPlatform {
cargo = toolchain;
rustc = toolchain;
};
in
rustPlatform.buildRustPackage {
pname = manifest.name;
version = manifest.version;
cargoLock.lockFile = ./Cargo.lock;
src = pkgs.lib.cleanSource ./.;
}
);
}
);
};
2021-04-07 00:17:50 +02:00
}