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

feat!: replace exclude from project docs with include in project docs, add project wide option for it #189

Merged
merged 2 commits into from
Jan 2, 2025
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
68 changes: 31 additions & 37 deletions src/implementation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
systemlessNci = args.config.nci;
inp = systemlessNci._inputs;
in {
# Make sure the top-level optiopn devshells exists
# Make sure the top-level option devshells exists
# even when the numtide devshell is not included.
# We don't want to depend on adding the numtide devshell
# module and this doesn't interfere with it when it is added.
Expand All @@ -30,9 +30,24 @@ in {
crate = getModuleDefaults ./modules/crate.nix;
project = getModuleDefaults ./modules/project.nix;
};
# gets crate option, if null or is not defined then returns the project wide option, if also does not exist then returns module default
_getCrateOption = crateName: optName: merge: let
crate = nci.crates.${crateName} or moduleDefaults.crate;
project = nci.projects.${cratesToProjects.${crateName} or crateName} or moduleDefaults.project;
in
if crate.${optName} == null
then project.${optName} or null
else if merge && l.isList crate.${optName}
then project.${optName} ++ crate.${optName}
else if merge && l.isAttrs crate.${optName}
then project.${optName} // crate.${optName}
else crate.${optName};
getCrateOption = crateName: optName: _getCrateOption crateName optName true;
getUnmergedCrateOption = crateName: optName: _getCrateOption crateName optName false;

nci = config.nci;

# project name -> nci crate cfg
projectsToCrates =
l.mapAttrs
(
Expand All @@ -43,6 +58,7 @@ in {
}
)
nci.projects;
# crate name -> project name
cratesToProjects = l.listToAttrs (l.flatten (
l.mapAttrsToList
(
Expand All @@ -52,23 +68,15 @@ in {
projectsToCrates
));
getCrateName = currentName: let
newName = nci.crates.${currentName}.renameTo or moduleDefaults.crate.renameTo;
newName = getCrateOption currentName "renameTo";
in
if newName != null
then newName
else currentName;

outputsToExport =
l.filterAttrs
(
name: out: let
crateExport = nci.crates.${name}.export or moduleDefaults.crate.export;
projectExport = nci.projects.${cratesToProjects.${name} or name}.export;
in
if crateExport == null
then projectExport
else crateExport
)
(name: out: getCrateOption name "export")
nci.outputs;

projectsChecked =
Expand Down Expand Up @@ -196,25 +204,12 @@ in {
l.mapAttrs
(
name: package: let
project = nci.projects.${cratesToProjects.${name}} or moduleDefaults.project;
crate = nci.crates.${name} or moduleDefaults.crate;
getOption = name: merge:
if (crate.${name} or null) == null
then project.${name}
else if merge
then
if l.isList crate.${name}
then project.${name} ++ crate.${name}
else if l.isAttrs crate.${name}
then project.${name} // crate.${name}
else crate.${name}
else crate.${name};
runtimeLibs = getOption "runtimeLibs" true;
profiles = getOption "profiles" true;
targets = getOption "targets" false;
clippyProfile = getOption "clippyProfile" false;
checkProfile = getOption "checkProfile" false;
docsProfile = getOption "docsProfile" false;
runtimeLibs = getCrateOption name "runtimeLibs";
profiles = getCrateOption name "profiles";
targets = getUnmergedCrateOption name "targets";
clippyProfile = getCrateOption name "clippyProfile";
checkProfile = getCrateOption name "checkProfile";
docsProfile = getCrateOption name "docsProfile";
allTargets = import ./functions/mkPackagesFromRaw.nix {
inherit pkgs runtimeLibs profiles targets;
rawPkg = package;
Expand Down Expand Up @@ -264,14 +259,13 @@ in {
indexCrateName = project.docsIndexCrate;
docsPackages =
l.map
(name: crateOutputs.${name}.docs)
(crateName: crateOutputs.${crateName}.docs)
(
l.filter
(name:
!(
nci.crates.${name}.excludeFromProjectDocs
or moduleDefaults.crate.excludeFromProjectDocs
))
(
crateName:
getCrateOption crateName "includeInProjectDocs"
)
allCrateNames
);
};
Expand All @@ -280,7 +274,7 @@ in {
++ (
l.flatten (
l.map
(name: nci.crates.${name}.runtimeLibs or moduleDefaults.crate.runtimeLibs)
(name: getCrateOption name "runtimeLibs")
allCrateNames
)
);
Expand Down
10 changes: 5 additions & 5 deletions src/modules/crate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ in {
example = "custom-profile";
description = "Profile to use for the docs only package";
};
excludeFromProjectDocs = l.mkOption {
type = t.bool;
default = false;
example = true;
description = "Whether to exclude this crate's docs from project docs package";
includeInProjectDocs = l.mkOption {
type = t.nullOr t.bool;
default = null;
example = false;
description = "Whether to include this crate's docs in the project docs package";
};

profiles = l.mkOption {
Expand Down
5 changes: 5 additions & 0 deletions src/modules/project.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ in {
default = "release";
example = "custom-profile";
};
includeInProjectDocs = mkOpt "includeInProjectDocs" {
type = t.bool;
default = true;
example = false;
};
docsIndexCrate = l.mkOption {
type = t.nullOr t.str;
default = null;
Expand Down
Loading