Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make option docs evaluate #25

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,21 @@
crane.url = "github:ipetkov/crane";
crane.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { rust-overlay, crane, ... }: {
outputs = { rust-overlay, crane, ... }:
let
# Preserve name and key of the module file for dedup and error message locations
import' =
modulePath: staticArg:
{
key = toString modulePath;
_file = toString modulePath;
imports = [ (import modulePath staticArg) ];
};
in
{
flakeModules = {
default = import ./nix/modules/flake-module.nix { inherit rust-overlay crane; };
nixpkgs = import ./nix/modules/nixpkgs.nix;
default = import' ./nix/modules/flake-module.nix { inherit rust-overlay crane; };
nixpkgs = ./nix/modules/nixpkgs.nix;
};
nixci.default =
let
Expand Down
29 changes: 28 additions & 1 deletion nix/modules/crate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
options = {
path = lib.mkOption {
type = lib.types.path;
description = "The path to the crate folder";
};
cargoToml = lib.mkOption {
type = lib.types.attrsOf lib.types.raw;
default = builtins.fromTOML (builtins.readFile ("${config.path}/Cargo.toml"));
description = "The parsed Cargo.toml file";
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 +53,9 @@
pkg-config
makeWrapper
];
defaultText = lib.literalExample ''
with pkgs; [ pkg-config makeWrapper ]
'';
description = "nativeBuildInputs for the cargo package";
};
};
Expand Down Expand Up @@ -113,35 +121,54 @@
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_";
};
};

packages = lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.package;
description = "All Nix packages for the Rust crate";
default = lib.mergeAttrs
(lib.optionalAttrs (lib.elem "crate" config.autoWire) {
${name} = config.crane.outputs.drv.crate;
})
(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;
description = "All Nix flake checks for the Rust crate";
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
13 changes: 13 additions & 0 deletions nix/modules/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ in

crane-lib = lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.raw;
description = ''
The value of `crane.mkLib pkgs` providing crane library functions
'';
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 +46,9 @@ in
"clippy"
];
};
defaultText = lib.literalMD ''
Based on the `rust-toolchain.toml` file in the flake directory
'';
};

crateNixFile = lib.mkOption {
Expand All @@ -67,6 +74,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 +85,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