diff options
author | Franck Cuny <franck@fcuny.net> | 2022-11-04 18:56:42 -0700 |
---|---|---|
committer | Franck Cuny <franck@fcuny.net> | 2022-11-04 18:56:42 -0700 |
commit | d06b527c0442787305b371196f8ea0fac115699b (patch) | |
tree | e321d99c1dc18d03ccf4f4efa1914a7586ab7b19 /templates/rust | |
parent | Merge pull request #2 from fcuny/fcuny/rust-template (diff) | |
download | world-d06b527c0442787305b371196f8ea0fac115699b.tar.gz |
ref: update rust's template to use crane
Diffstat (limited to 'templates/rust')
-rw-r--r-- | templates/rust/flake.nix | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix index b6bc262..fdce743 100644 --- a/templates/rust/flake.nix +++ b/templates/rust/flake.nix @@ -11,6 +11,10 @@ nixpkgs.follows = "nixpkgs"; }; }; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; pre-commit-hooks = { url = "github:cachix/pre-commit-hooks.nix"; inputs = { @@ -25,43 +29,45 @@ , flake-utils , nixpkgs , rust-overlay + , crane , pre-commit-hooks }: - let - # Borrow project metadata from the Rust config - meta = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package; - inherit (meta) name version; - overlays = [ - # Rust helpers - (import rust-overlay) - # Build Rust toolchain using helpers from rust-overlay - (self: super: { - # This supplies cargo, rustc, rustfmt, etc. - rustToolchain = super.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; - }) - ]; - in flake-utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { inherit system overlays; }; + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + + craneLib = (crane.mkLib pkgs).overrideScope' (_: _: { + cargo = rust-toolchain; + clippy = rust-toolchain; + rustc = rust-toolchain; + rustfmt = rust-toolchain; + }); + + src = ./.; + + cargoArtifacts = craneLib.buildDepsOnly { + inherit src; + }; + + my-crate = craneLib.buildPackage { + inherit cargoArtifacts src; + }; in { - packages = rec { - default = XXX; - x509-info = pkgs.rustPlatform.buildRustPackage { - pname = name; - inherit version; - src = ./.; - release = true; - cargoLock.lockFile = ./Cargo.lock; - }; + packages.default = my-crate; + apps.default = flake-utils.lib.mkApp { + drv = my-crate; }; checks = { pre-commit = pre-commit-hooks.lib.${system}.run { - src = ./.; + inherit src; hooks = { clippy = { enable = true; @@ -80,8 +86,7 @@ devShell = pkgs.mkShell { nativeBuildInputs = with pkgs; [ - rustToolchain - cargo-audit + rust-toolchain cargo-deny rust-analyzer ]; |