From a09e680fa05aa13514c875ac6e66a3ad3c7e15ad Mon Sep 17 00:00:00 2001 From: Qubasa Date: Wed, 1 May 2024 23:35:14 +0200 Subject: [PATCH] Require README.md for every clan module --- clanModules/syncthing/README.md | 2 +- docs/nix/get-module-docs.nix | 2 +- lib/description.nix | 23 +++++++++++++++-------- pkgs/schemas/flake-module.nix | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/clanModules/syncthing/README.md b/clanModules/syncthing/README.md index 6f719e78..f1da99c9 100644 --- a/clanModules/syncthing/README.md +++ b/clanModules/syncthing/README.md @@ -1,7 +1,7 @@ Syncthing is a free, open-source file synchronization application designed to allow users to synchronize files between multiple devices over the internet or local networks securely and privately. It is an alternative to cloud-based file sharing services. - +--- ## Usage We recommend configuring this module as an sync-service through the provided options. Although it provides a Web GUI through which more usage scenarios are supported. diff --git a/docs/nix/get-module-docs.nix b/docs/nix/get-module-docs.nix index 25e67a88..830e52fa 100644 --- a/docs/nix/get-module-docs.nix +++ b/docs/nix/get-module-docs.nix @@ -38,7 +38,7 @@ let ) clanModules; clanModulesReadmes = builtins.mapAttrs ( - module_name: _module: self.lib.modules.getDescription module_name + module_name: _module: self.lib.modules.getReadme module_name ) clanModules; # clanCore docs diff --git a/lib/description.nix b/lib/description.nix index 0cd30218..deb315b4 100644 --- a/lib/description.nix +++ b/lib/description.nix @@ -1,19 +1,26 @@ { clan-core, ... }: -{ - getDescription = +rec { + getReadme = modulename: let readme = "${clan-core}/clanModules/${modulename}/README.md"; readmeContents = - if - builtins.trace "Trying to get Module README.md for ${modulename} from ${readme}" - # TODO: Edge cases - (builtins.pathExists readme) - then + if (builtins.pathExists readme) then (builtins.readFile readme) else - null; + throw "No README.md found for module ${modulename}"; in readmeContents; + + getShortDescription = + modulename: + let + content = (getReadme modulename); + parts = builtins.split "---" content; + in + if (builtins.length parts) > 0 then + builtins.head parts + 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 c0be5826..c124f44a 100644 --- a/pkgs/schemas/flake-module.nix +++ b/pkgs/schemas/flake-module.nix @@ -38,7 +38,7 @@ clanModuleFunctionSchemas = lib.mapAttrsFlatten (modulename: module: { name = modulename; - description = self.lib.modules.getDescription modulename; + description = self.lib.modules.getShortDescription modulename; parameters = self.lib.jsonschema.parseOptions (optionsFromModule modulename module); }) clanModules; in