diff --git a/flake.lock b/flake.lock index b6481e1..d58f25e 100644 --- a/flake.lock +++ b/flake.lock @@ -262,9 +262,30 @@ "crane": "crane", "flake-parts": "flake-parts", "nixpkgs": "nixpkgs_2", + "rust-overlay": "rust-overlay", "treefmt-nix": "treefmt-nix" } }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1780197589, + "narHash": "sha256-FVCr2Ij/jKf59a4LW481eeOF6rJRreOBrVgW/aUBTrw=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "21632e942d89bf1cce4e5a63d7e58a215a0cbfcc", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, "systems": { "locked": { "lastModified": 1681028828, diff --git a/flake.nix b/flake.nix index 88f5354..81c97a3 100644 --- a/flake.nix +++ b/flake.nix @@ -13,6 +13,11 @@ crane.url = "github:ipetkov/crane"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + cadquery = { url = "github:vinszent/cq-flake"; # unfortunately dependencies are out of date so this needs it's own nixpkgs diff --git a/rust/default.nix b/rust/default.nix index 9b5611a..beaa8f8 100644 --- a/rust/default.nix +++ b/rust/default.nix @@ -25,10 +25,17 @@ }: let cfg = config.krantz.rust; - craneLib = inputs.crane.mkLib pkgs; src = cfg.srcFiltered; manifest = (lib.importTOML "${src}/Cargo.toml").package; + craneLib = + if builtins.pathExists cfg.srcToolchain + then + (inputs.crane.mkLib (pkgs.extend inputs.rust-overlay.overlays.default)).overrideToolchain ( + p: p.rust-bin.fromRustupToolchainFile cfg.srcToolchain + ) + else inputs.crane.mkLib pkgs; + buildInputs = cfg.runtimeDeps; # build dependencies @@ -55,6 +62,13 @@ defaultText = lib.literalExpression "config.krantz.rust.craneLib cfg.src"; example = lib.literalExpression "./."; }; + srcToolchain = lib.mkOption { + description = "A path to the rust-toolchain(.toml) file for the repo. Will use the toolchain from nixpkgs if the file does not exist."; + type = lib.types.path; + default = "${cfg.src}/rust-toolchain.toml"; + defaultText = lib.literalExpression "cfg.src + \"/rust-toolchain.toml\""; + example = lib.literalExpression "./rust-toolchain"; + }; runtimeDeps = lib.mkOption { description = "Packages needed for the app to run.";