From 60448993c599009213ba4618bc053e81e83577c3 Mon Sep 17 00:00:00 2001 From: Reed Krantz Date: Wed, 10 Jun 2026 21:21:16 -0500 Subject: [PATCH] refactor(rust): update the way the rust.srcToolchain default works and also some defaultText --- rust/default.nix | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/rust/default.nix b/rust/default.nix index 84b0731..0028e8b 100644 --- a/rust/default.nix +++ b/rust/default.nix @@ -29,7 +29,7 @@ manifest = (lib.importTOML "${src}/Cargo.toml").package; craneLib = - if builtins.pathExists cfg.srcToolchain + if cfg.srcToolchain != null && builtins.pathExists cfg.srcToolchain then (inputs.crane.mkLib (pkgs.extend inputs.rust-overlay.overlays.default)).overrideToolchain ( p: p.rust-bin.fromRustupToolchainFile cfg.srcToolchain @@ -61,18 +61,26 @@ description = "A path to the filtered directory of the root of the crate."; type = lib.types.path; default = craneLib.cleanCargoSource cfg.src; - defaultText = lib.literalExpression "config.krantz.rust.craneLib cfg.src"; + defaultText = lib.literalExpression "config.krantz.rust.craneLib.cleanCargoSource 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 = "${ + type = lib.types.nullOr lib.types.path; + default = if cfg.src != null - then cfg.src - else "/dev/null" - }/rust-toolchain.toml"; - defaultText = lib.literalExpression "cfg.src + \"/rust-toolchain.toml\""; + then cfg.src + "/rust-toolchain.toml" + else null; + defaultText = + lib.literalExpression + /* + nix + */ + '' + if cfg.src != null + then cfg.src + "/rust-toolchain.toml" + else null; + ''; example = lib.literalExpression "./rust-toolchain"; };