From d488feb4b2a586071fdb28309858747549670903 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Thu, 8 Dec 2022 09:11:49 +0100 Subject: treewide: fmt with alejandra --- documentation-highlighter/default.nix | 7 +- flake.nix | 199 +++++++++++++++++++--------------- manpage.nix | 31 +++--- mdbook.nix | 131 +++++++++++----------- 4 files changed, 206 insertions(+), 162 deletions(-) diff --git a/documentation-highlighter/default.nix b/documentation-highlighter/default.nix index 2a34e36..dbba883 100644 --- a/documentation-highlighter/default.nix +++ b/documentation-highlighter/default.nix @@ -1,11 +1,14 @@ -{ lib, runCommand }: +{ + lib, + runCommand, +}: runCommand "documentation-highlighter" { meta = { description = "Highlight.js sources for the Nix Ecosystem's documentation"; homepage = "https://highlightjs.org"; license = lib.licenses.bsd3; platforms = lib.platforms.all; - maintainers = [ lib.maintainers.grahamc ]; + maintainers = [lib.maintainers.grahamc]; }; } '' cp -r ${./.} $out diff --git a/flake.nix b/flake.nix index 2826989..d4ac128 100644 --- a/flake.nix +++ b/flake.nix @@ -3,102 +3,131 @@ inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05"; - outputs = { self, nixpkgs }: - let pkgs = nixpkgs.legacyPackages.x86_64-linux; - in - { + outputs = { + self, + nixpkgs, + }: let + pkgs = nixpkgs.legacyPackages.x86_64-linux; + in { + lib.modules = { + doc-options-md = import ./doc-options-md.nix; + mdbook = import ./mdbook.nix; + manpage = import ./manpage.nix; + }; - lib.modules = { - doc-options-md = import ./doc-options-md.nix; - mdbook = import ./mdbook.nix; - manpage = import ./manpage.nix; + checks.x86_64-linux = let + evalModules = modules: + pkgs.lib.evalModules { + modules = + [ + {config._module.args = {inherit pkgs;};} + ] + ++ modules; + }; + simpleModule = with pkgs.lib; { + options.my.simple.module.outputs = mkOption { + type = with types; attrsOf package; + default = {}; + description = '' + Output products of my simple module system. + ''; + }; + }; + params = { + outputAttrPath = ["my" "simple" "module" "outputs"]; + optionsAttrPath = ["my" "simple" "module" "doc"]; + optionsInternal = false; }; - checks.x86_64-linux = - let - evalModules = modules: pkgs.lib.evalModules { - modules = [ - ({ config._module.args = { inherit pkgs; }; }) - ] ++ modules; - }; - simpleModule = with pkgs.lib; { - options.my.simple.module.outputs = mkOption { - type = with types; attrsOf package; - default = { }; - description = '' - Output products of my simple module system. - ''; - }; - }; - params = { - outputAttrPath = [ "my" "simple" "module" "outputs" ]; - optionsAttrPath = [ "my" "simple" "module" "doc" ]; - optionsInternal = false; - }; - - simple-manpage = { - name = "my simple module system"; - shortDescription = "A sample module system"; - }; - - advanced-manpage = { - name = "my simple module system"; - section = 5; - shortDescription = "A sample module system"; - description = '' - This is a very advanced module system, for advanced people. - ''; + simple-manpage = { + name = "my simple module system"; + shortDescription = "A sample module system"; + }; - textBefore = '' - # A SECTION BEFORE + advanced-manpage = { + name = "my simple module system"; + section = 5; + shortDescription = "A sample module system"; + description = '' + This is a very advanced module system, for advanced people. + ''; - This is a section before the options. - ''; + textBefore = '' + # A SECTION BEFORE - textAfter = '' - # A SECTION AFTER + This is a section before the options. + ''; - This is a section after the options. - ''; - }; - in - { - simple-doc-options-md = (evalModules [ - simpleModule - (self.lib.modules.doc-options-md params) - ]).config.my.simple.module.outputs.doc-options-md; + textAfter = '' + # A SECTION AFTER - simple-manpage = (evalModules [ - simpleModule - (self.lib.modules.doc-options-md params) - (self.lib.modules.manpage params) - { - my.simple.module.doc.manpage = simple-manpage; - } - ]).config.my.simple.module.outputs.manpage; + This is a section after the options. + ''; + }; + in { + simple-doc-options-md = + (evalModules [ + simpleModule + (self.lib.modules.doc-options-md params) + ]) + .config + .my + .simple + .module + .outputs + .doc-options-md; - advanced-manpage = (evalModules [ - simpleModule - (self.lib.modules.doc-options-md params) - (self.lib.modules.manpage params) - { - my.simple.module.doc.manpage = advanced-manpage; - } - ]).config.my.simple.module.outputs.manpage; + simple-manpage = + (evalModules [ + simpleModule + (self.lib.modules.doc-options-md params) + (self.lib.modules.manpage params) + { + my.simple.module.doc.manpage = simple-manpage; + } + ]) + .config + .my + .simple + .module + .outputs + .manpage; - simple-mdbook = (evalModules [ - simpleModule - (self.lib.modules.doc-options-md params) - (self.lib.modules.mdbook params) - { - my.simple.module.doc.mdbook.src = ./checks/simple-mdbook; - } - ]).config.my.simple.module.outputs.mdbook; + advanced-manpage = + (evalModules [ + simpleModule + (self.lib.modules.doc-options-md params) + (self.lib.modules.manpage params) + { + my.simple.module.doc.manpage = advanced-manpage; + } + ]) + .config + .my + .simple + .module + .outputs + .manpage; - }; + simple-mdbook = + (evalModules [ + simpleModule + (self.lib.modules.doc-options-md params) + (self.lib.modules.mdbook params) + { + my.simple.module.doc.mdbook.src = ./checks/simple-mdbook; + } + ]) + .config + .my + .simple + .module + .outputs + .mdbook; + }; - devShell.x86_64-linux = pkgs.mkShell { - nativeBuildInputs = with pkgs; [ mdbook pandoc ]; - }; + devShell.x86_64-linux = pkgs.mkShell { + nativeBuildInputs = with pkgs; [mdbook pandoc]; }; + }; } diff --git a/manpage.nix b/manpage.nix index bea6b25..c47d88a 100644 --- a/manpage.nix +++ b/manpage.nix @@ -1,13 +1,16 @@ -{ outputAttrPath, optionsAttrPath, optionsInternal ? true, }: - -{ config, lib, pkgs, ... }: - -with lib; - -let - cfg = getAttrFromPath (optionsAttrPath ++ [ "manpage" ]) config; -in { + outputAttrPath, + optionsAttrPath, + optionsInternal ? true, +}: { + config, + lib, + pkgs, + ... +}: +with lib; let + cfg = getAttrFromPath (optionsAttrPath ++ ["manpage"]) config; +in { options = setAttrByPath optionsAttrPath { manpage = { name = mkOption { @@ -93,12 +96,12 @@ in default = ""; internal = optionsInternal; }; - }; }; config = setAttrByPath outputAttrPath { - manpage = pkgs.runCommand cfg.file + manpage = + pkgs.runCommand cfg.file { src = pkgs.writeText "${cfg.file}.md" '' % ${cfg.title} @@ -128,9 +131,9 @@ in ${cfg.textAfter} ''; - nativeBuildInputs = [ pkgs.pandoc ]; + nativeBuildInputs = [pkgs.pandoc]; } '' - pandoc "$src" --from=markdown --to=man --standalone --output="$out" - ''; + pandoc "$src" --from=markdown --to=man --standalone --output="$out" + ''; }; } diff --git a/mdbook.nix b/mdbook.nix index e55606a..931dbc1 100644 --- a/mdbook.nix +++ b/mdbook.nix @@ -1,15 +1,18 @@ -{ outputAttrPath, optionsAttrPath, optionsInternal ? true, }: - -{ config, lib, pkgs, ... }: - -with lib; - -let - cfg = getAttrFromPath (optionsAttrPath ++ [ "mdbook" ]) config; - - documentation-highlighter = pkgs.callPackage ./documentation-highlighter { }; -in { + outputAttrPath, + optionsAttrPath, + optionsInternal ? true, +}: { + config, + lib, + pkgs, + ... +}: +with lib; let + cfg = getAttrFromPath (optionsAttrPath ++ ["mdbook"]) config; + + documentation-highlighter = pkgs.callPackage ./documentation-highlighter {}; +in { options = setAttrByPath optionsAttrPath { mdbook = { src = mkOption { @@ -21,40 +24,45 @@ in }; pages = mkOption { - type = with types; attrsOf (submodule ({ name, config, ... }: { - options = { - target = mkOption { - type = types.str; - default = name; - description = '' - Where to install the page, relative to the `src/` directory. - ''; - internal = optionsInternal; - }; - - text = mkOption { - type = types.lines; - description = '' - Content of the page. - ''; - internal = optionsInternal; + type = with types; + attrsOf (submodule ({ + name, + config, + ... + }: { + options = { + target = mkOption { + type = types.str; + default = name; + description = '' + Where to install the page, relative to the `src/` directory. + ''; + internal = optionsInternal; + }; + + text = mkOption { + type = types.lines; + description = '' + Content of the page. + ''; + internal = optionsInternal; + }; + + source = mkOption { + type = types.path; + description = '' + Path of the source file for this page. + + If both `text` and `source` are defined, `source` takes + precedence. + ''; + internal = optionsInternal; + }; }; - source = mkOption { - type = types.path; - description = '' - Path of the source file for this page. - - If both `text` and `source` are defined, `source` takes - precedence. - ''; - internal = optionsInternal; - }; - }; - - config.source = mkDefault (pkgs.writeText name config.text); - })); - default = { }; + config.source = mkDefault (pkgs.writeText name config.text); + })); + default = {}; example = { "my-page.md".text = '' # Title @@ -89,44 +97,45 @@ in }; config = mkMerge [ - (setAttrByPath (optionsAttrPath ++ [ "mdbook" ]) { + (setAttrByPath (optionsAttrPath ++ ["mdbook"]) { pages."options.md".text = '' # Available options You can use the following options: - ${readFile (getAttrFromPath (outputAttrPath ++ [ "doc-options-md" ]) config)} + ${readFile (getAttrFromPath (outputAttrPath ++ ["doc-options-md"]) config)} ''; }) (setAttrByPath outputAttrPath { # TODO: make pandoc pre-processor - mdbook = pkgs.runCommand "mdbook" + mdbook = + pkgs.runCommand "mdbook" { src = cfg.src; - nativeBuildInputs = with pkgs; [ mdbook ]; + nativeBuildInputs = with pkgs; [mdbook]; } '' - unpackFile "$src" - chmod -R u+w . - cd */ + unpackFile "$src" + chmod -R u+w . + cd */ - mkdir theme - cp ${documentation-highlighter}/highlight.min.js theme/highlight.js - cp ${documentation-highlighter}/mono-blue.min.css theme/highlight.css + mkdir theme + cp ${documentation-highlighter}/highlight.min.js theme/highlight.js + cp ${documentation-highlighter}/mono-blue.min.css theme/highlight.css - ${concatMapStrings (page: '' - cp "${page.source}" "src/${page.target}" - '') (attrValues cfg.pages)} + ${concatMapStrings (page: '' + cp "${page.source}" "src/${page.target}" + '') (attrValues cfg.pages)} - ${cfg.preBuild} + ${cfg.preBuild} - mdbook build + mdbook build - ${cfg.postBuild} + ${cfg.postBuild} - cp -r book "$out" - ''; + cp -r book "$out" + ''; }) ]; } -- cgit v1.2.3