Skip to content

Commit

Permalink
fix: Make option docs evaluate
Browse files Browse the repository at this point in the history
Some defaults should probably be normal definitions or `lib.mkDefault`
definitions in the config section. They don't all make sense to be
documented defaults.

However, I've solved it with some less than optimal descriptions in
order not to move code around. Maybe I should have just moved it?
  • Loading branch information
roberth committed Sep 28, 2024
1 parent f5876f2 commit 02cc2b2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
25 changes: 24 additions & 1 deletion nix/modules/crate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
};
cargoToml = lib.mkOption {
type = lib.types.attrsOf lib.types.raw;
default = builtins.fromTOML (builtins.readFile ("${config.path}/Cargo.toml"));
default = builtins.fromTOML (builtins.readFile (config.path + "/Cargo.toml"));
defaultText = lib.literalExpression ''
fromTOML (readFile (path + "/Cargo.toml"))
'';
};
autoWire =
let
Expand Down Expand Up @@ -48,6 +51,9 @@
pkg-config
makeWrapper
];
defaultText = lib.literalExample ''
with pkgs; [ pkg-config makeWrapper ]
'';
description = "nativeBuildInputs for the cargo package";
};
};
Expand Down Expand Up @@ -113,16 +119,19 @@
type = lib.types.package;
description = "The Nix package for the Rust crate";
default = craneBuild.package;
defaultText = lib.literalMD "_computed with crane_";
};
doc = lib.mkOption {
type = lib.types.package;
description = "The Nix package for the Rust crate documentation";
default = craneBuild.doc;
defaultText = lib.literalMD "_computed with crane_";
};
clippy = lib.mkOption {
type = lib.types.package;
description = "The Nix package for the Rust crate clippy check";
default = craneBuild.check;
defaultText = lib.literalMD "_computed with crane_";
};
};

Expand All @@ -135,13 +144,27 @@
(lib.optionalAttrs (lib.elem "doc" config.autoWire) {
"${name}-doc" = config.crane.outputs.drv.doc;
});
defaultText = lib.literalMD ''
lib.mergeAttrs
(optionalAttrs (elem "crate" config.autoWire) {
"''${name}" = config.crane.outputs.drv.crate;
})
(optionalAttrs (elem "doc" config.autoWire) {
"''${name}-doc" = config.crane.outputs.drv.doc;
})
'';
};

checks = lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.package;
default = lib.optionalAttrs (lib.elem "clippy" config.autoWire && crane.clippy.enable) {
"${name}-clippy" = config.crane.outputs.drv.clippy;
};
defaultText = lib.literalExample ''
optionalAttrs (elem "clippy" config.autoWire && crane.clippy.enable) {
"''${name}-clippy" = config.crane.outputs.drv.clippy;
}
'';
};
};
};
Expand Down
10 changes: 10 additions & 0 deletions nix/modules/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ in
crane-lib = lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.raw;
default = (rustFlakeInputs.crane.mkLib pkgs).overrideToolchain config.rust-project.toolchain;
defaultText = lib.literalExpression "computed from `rust-flake.inputs.crane` and [`perSystem.rust-project.toolchain`](#opt-perSystem.rust-project.toolchain)";
};
toolchain = lib.mkOption {
type = lib.types.package;
Expand All @@ -42,6 +43,9 @@ in
"clippy"
];
};
defaultText = lib.literalMD ''
Based on the `rust-toolchain.toml` file in the flake directory
'';
};

crateNixFile = lib.mkOption {
Expand All @@ -67,6 +71,9 @@ in
(config.rust-project.crane-lib.filterCargoSources path type)
;
};
defaultText = lib.literalMD ''
Files in this flake (`self`) filtered by crane
'';
};

cargoToml = lib.mkOption {
Expand All @@ -75,6 +82,9 @@ in
Cargo.toml parsed in Nix
'';
default = builtins.fromTOML (builtins.readFile (self + /Cargo.toml));
defaultText = lib.literalExpression ''
fromTOML (readFile (self + "/Cargo.toml"))
'';
};
};
};
Expand Down

0 comments on commit 02cc2b2

Please sign in to comment.