diff --git a/lib/default.nix b/lib/default.nix index 30b68b5c..086fcce8 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -8,7 +8,6 @@ evalClanModules = import ./eval-clan-modules { inherit clan-core nixpkgs lib; }; inventory = import ./inventory { inherit lib clan-core; }; jsonschema = import ./jsonschema { inherit lib; }; - # TODO: migrate to also use toml frontmatter - # modules = import ./description.nix { inherit clan-core lib; }; + modules = import ./description.nix { inherit clan-core lib; }; buildClan = import ./build-clan { inherit clan-core lib nixpkgs; }; } diff --git a/lib/description.nix b/lib/description.nix index 917836f0..c4c641e6 100644 --- a/lib/description.nix +++ b/lib/description.nix @@ -1,33 +1,34 @@ -{ ... }: - +{ clan-core, lib }: rec { - # getReadme = - # modulename: - # let - # readme = "${clan-core}/clanModules/${modulename}/README.md"; - # readmeContents = - # if (builtins.pathExists readme) then - # (builtins.readFile readme) - # else - # throw "No README.md found for module ${modulename}"; - # in - # readmeContents; + getReadme = + modulename: + let + readme = "${clan-core}/clanModules/${modulename}/README.md"; + readmeContents = + if (builtins.pathExists readme) then + (builtins.readFile readme) + else + throw "No README.md found for module ${modulename}"; + in + readmeContents; - # getShortDescription = - # modulename: - # let - # content = (getReadme modulename); - # parts = lib.splitString "---" content; - # description = builtins.head parts; - # number_of_newlines = builtins.length (lib.splitString "\n" description); - # in - # if (builtins.length parts) > 1 then - # if number_of_newlines > 4 then - # throw "Short description in README.md for module ${modulename} is too long. Max 3 newlines." - # else if number_of_newlines <= 1 then - # throw "Missing short description in README.md for module ${modulename}." - # else - # description - # else - # throw "Short description delimiter `---` not found in README.md for module ${modulename}"; + getShortDescription = + modulename: + let + content = getReadme modulename; + parts = lib.splitString "---" content; + # Partition the parts into the first part (the readme content) and the rest (the metadata) + parsed = builtins.partition ({ index }: if index >= 2 then false else true) ( + lib.filter ({ index, ... }: index != 0) (lib.imap0 (index: part: { inherit index part; }) parts) + ); + + # Use this if the content is needed + # readmeContent = lib.concatMapStrings (v: "---" + v.part) parsed.wrong; + + meta = builtins.fromTOML (builtins.head parsed.right).part; + in + if (builtins.length parts >= 3) then + meta.description + else + throw "Short description delimiter `---` not found in README.md for module ${modulename}"; } diff --git a/pkgs/schemas/flake-module.nix b/pkgs/schemas/flake-module.nix index 89d75577..59c25d01 100644 --- a/pkgs/schemas/flake-module.nix +++ b/pkgs/schemas/flake-module.nix @@ -23,8 +23,7 @@ clanModuleFunctionSchemas = lib.mapAttrsFlatten (modulename: _: { name = modulename; - # TODO: migrate to new toml format - # description = self.lib.modules.getShortDescription modulename; + description = self.lib.modules.getShortDescription modulename; parameters = self.lib.jsonschema.parseOptions (optionsFromModule modulename); }) clanModules; in