{ pkgs, lib, inputs, ... }: let nixosConfiguration = lib.nixosSystem { inherit (pkgs) system; modules = [ inputs.home-manager.nixosModules.home-manager inputs.self.nixosModules.stylix ./settings.nix ]; }; homeManagerConfiguration = inputs.home-manager.lib.homeManagerConfiguration { inherit pkgs; modules = [ inputs.self.homeManagerModules.stylix ./settings.nix { home = { homeDirectory = "/home/book"; stateVersion = "22.11"; username = "book"; }; } ]; }; # TODO: Include Nix Darwin options platforms = { home_manager = { name = "Home Manager"; configuration = homeManagerConfiguration; }; nixos = { name = "NixOS"; configuration = nixosConfiguration; }; }; # We construct an index of all Stylix options, using the following format: # # { # "src/options/modules/«module».md" = { # referenceSection = "Modules"; # readme = "modules/«module»/README.md"; # defaultReadme = "note about the path above not existing"; # optionsByPlatform = { # home_manager = [ ... ]; # nixos = [ ... ]; # }; # }; # # "src/options/platforms/«platform».md" = { # referenceSection = "Platforms"; # readme = "docs/src/options/platforms/«platform».md"; # defaultReadme = "note about the path above not existing"; # optionsByPlatform.«platform» = [ ... ]; # }; # } # # Options are inserted one at a time into the appropriate page, creating # new page entries if they don't exist. insert = { index, page, emptyPage, platform, option, }: index // { ${page} = let oldPage = index.${page} or emptyPage; in oldPage // { optionsByPlatform = oldPage.optionsByPlatform // { ${platform} = oldPage.optionsByPlatform.${platform} ++ [ option ]; }; }; }; insertDeclaration = { index, declaration, platform, option, }: # Only include options which are declared by a module within Stylix. if lib.hasPrefix "${inputs.self}/" declaration then let # Part of this string may become an attribute name in the index, and # attribute names aren't allowed to have string context. The context # comes from `${inputs.self}`, which is removed by `removePrefix`. # Therefore, this use of `unsafeDiscardStringContext` is safe. pathWithContext = lib.removePrefix "${inputs.self}/" declaration; path = builtins.unsafeDiscardStringContext pathWithContext; pathComponents = lib.splitString "/" path; in # Options declared in the modules directory go to the Modules section, # otherwise they're assumed to be shared between modules, and go to the # Platforms section. if builtins.elemAt pathComponents 0 == "modules" then let module = builtins.elemAt pathComponents 1; in insert { inherit index platform option; page = "src/options/modules/${module}.md"; emptyPage = { referenceSection = "Modules"; readme = "${inputs.self}/modules/${module}/README.md"; defaultReadme = '' # ${module} > [!NOTE] > This module doesn't include any additional documentation. You > can browse the options it provides below. ''; # Module pages initialise all platforms to an empty list, so that # '*None provided.*' indicates platforms where the module isn't # available. optionsByPlatform = lib.mapAttrs (_: _: [ ]) platforms; }; } else insert { inherit index platform option; page = "src/options/platforms/${platform}.md"; emptyPage = { referenceSection = "Platforms"; readme = "${inputs.self}/docs/src/options/platforms/${platform}.md"; defaultReadme = '' # ${platform.name} > Documentation is not available for this platform. Its main > options are listed below, and you may find more specific options > in the documentation for each module. ''; # Platform pages only initialise that platform, since showing other # platforms here would be nonsensical. optionsByPlatform.${platform} = [ ]; }; } else index; insertOption = { index, platform, option, }: builtins.foldl' ( foldIndex: declaration: insertDeclaration { index = foldIndex; inherit declaration platform option; } ) index option.declarations; insertPlatform = index: platform: builtins.foldl' ( foldIndex: option: insertOption { index = foldIndex; inherit platform option; } ) index (lib.optionAttrSetToDocList platforms.${platform}.configuration.options); index = builtins.foldl' insertPlatform { } (builtins.attrNames platforms); # Renders a value, which should have been created with either lib.literalMD # or lib.literalExpression. renderValue = value: if lib.isType "literalMD" value then value.text else if lib.isType "literalExpression" value then '' ```nix ${value.text} ``` '' else builtins.throw "unexpected value type: ${builtins.typeOf value}"; # Prefix to remove from file paths when listing where an option is declared. declarationPrefix = "${inputs.self}"; # Permalink to view a source file on GitHub. If the commit isn't known, # then fall back to the latest commit. declarationCommit = inputs.self.rev or "master"; declarationPermalink = "https://github.com/danth/stylix/blob/${declarationCommit}"; # Renders a single option declaration. Example output: # # - [modules/module1/nixos.nix](https://github.com/danth/stylix/blob/«commit»/modules/module1/nixos.nix) renderDeclaration = declaration: let declarationString = toString declaration; filePath = lib.removePrefix "${declarationPrefix}/" declarationString; in if lib.hasPrefix declarationPrefix declarationString then "- [${filePath}](${declarationPermalink}/${filePath})" else builtins.throw "declaration not in ${declarationPrefix}: ${declarationString}"; # You can embed HTML inside a Markdown document, but to render further # Markdown within that HTML, it must be surrounded by blank lines. # This function helps with that. # # In the following functions, we use concatStrings to build embedded HTML, # rather than ${} and multiline strings, because Markdown is sensitive to # indentation and may render indented HTML as a code block. The easiest way # around this is to generate all the HTML on a single line. markdownInHTML = markdown: "\n\n" + markdown + "\n\n"; renderDetailsRow = name: value: lib.concatStrings [ "