From 757d027a4d6c8f42993299d3ff600809b91fab85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Thu, 21 Nov 2024 16:06:21 +0100 Subject: [PATCH] Initial Version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- .envrc | 1 + .gitignore | 8 ++++ flake.nix | 99 +++++++++++++++++++++++++++++++++++++++++++++ rust-toolchain.toml | 2 + rustfmt.toml | 3 ++ 5 files changed, 113 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 flake.nix create mode 100644 rust-toolchain.toml create mode 100644 rustfmt.toml diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..defb674 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# Rust/Cargo +/target + +# Direnv +/.direnv + +# Nix +/result* diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..c703695 --- /dev/null +++ b/flake.nix @@ -0,0 +1,99 @@ +{ + description = "library"; + inputs = { + nixpkgs.url = "nixpkgs/nixos-24.05"; + flake-utils = { + url = "github:numtide/flake-utils"; + }; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + }; + }; + + outputs = + inputs: + inputs.flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ (import inputs.rust-overlay) ]; + }; + + rustTarget = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + unstableRustTarget = pkgs.rust-bin.selectLatestNightlyWith ( + toolchain: + toolchain.default.override { + extensions = [ + "rust-src" + "miri" + "rustfmt" + ]; + } + ); + craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rustTarget; + unstableCraneLib = (inputs.crane.mkLib pkgs).overrideToolchain unstableRustTarget; + + tomlInfo = craneLib.crateNameFromCargoToml { cargoToml = ./Cargo.toml; }; + inherit (tomlInfo) version; + src = ./.; + + rustfmt' = pkgs.writeShellScriptBin "rustfmt" '' + exec "${unstableRustTarget}/bin/rustfmt" "$@" + ''; + + cargoArtifacts = craneLib.buildDepsOnly { + inherit src; + cargoExtraArgs = "--all-features --all"; + }; + + crate = craneLib.buildPackage { + inherit cargoArtifacts src version; + cargoExtraArgs = "--all-features --all"; + }; + + in + rec { + checks = { + inherit crate; + + crate-clippy = craneLib.cargoClippy { + inherit cargoArtifacts src; + cargoExtraArgs = "--all --all-features"; + cargoClippyExtraArgs = "-- --deny warnings"; + }; + + crate-fmt = unstableCraneLib.cargoFmt { + inherit src; + }; + }; + + packages.crate = crate; + packages.default = packages.crate; + + apps.crate = inputs.flake-utils.lib.mkApp { + name = "library"; + drv = crate; + }; + apps.default = apps.crate; + + devShells.default = devShells.crate; + devShells.crate = pkgs.mkShell { + buildInputs = [ ]; + + nativeBuildInputs = [ + rustfmt' + rustTarget + ]; + }; + } + ); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..2e2b8c8 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.82.0" diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..84d1a61 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,3 @@ +imports_granularity = "Item" +reorder_imports = true +group_imports = "StdExternalCrate"