{ pkgs, lib, inputs, ... }@args: 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; }; }; metadata = import "${inputs.self}/stylix/meta.nix" args; # We construct an index of all Stylix options, using the following format: # # { # "src/options/modules/«module».md" = { # referenceSection = "Modules"; # readme = '' # Content of modules/«module»/README.md, or a default title # followed by a note about that file not existing. # # Summary of module maintainers, or a warning that the module # is unmaintained. # ''; # optionsByPlatform = { # home_manager = [ ... ]; # nixos = [ ... ]; # }; # }; # # "src/options/platforms/«platform».md" = { # referenceSection = "Platforms"; # readme = '' # Content of docs/src/options/platforms/«platform».md, or a default # title followed by a note about that file 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 = let path = "${inputs.self}/modules/${module}/README.md"; # This doesn't count as IFD because ${inputs.self} is a flake input mainText = if builtins.pathExists path then builtins.readFile path else '' # ${module} > [!NOTE] > This module doesn't include any additional documentation. > You can browse the options it provides below. ''; inherit (metadata.${module}) maintainers; # Render a maintainer's name and a link to the best contact # information we have for them. # # The reasoning behind the order of preference is as follows: # # - GitHub: # - May link to multiple contact methods # - More likely to have up-to-date information than the # maintainers list # - Protects the email address from crawlers # - Email: # - Very commonly used # - Matrix: # - Only other contact method in the schema # (as of March 2025) # - Name: # - If no other information is available, then just show # the maintainer's name without a link renderMaintainer = maintainer: if maintainer ? github then "[${maintainer.name}](https://github.com/${maintainer.github})" else if maintainer ? email then "[${maintainer.name}](mailto:${maintainer.email})" else if maintainer ? matrix then "[${maintainer.name}](https://matrix.to/#/${maintainer.matrix})" else maintainer.name; joinItems = items: if builtins.length items <= 2 then builtins.concatStringsSep " and " items else builtins.concatStringsSep ", " ( lib.dropEnd 1 items ++ [ "and ${lib.last items}" ] ); renderedMaintainers = joinItems (map renderMaintainer maintainers); maintainersText = if maintainers == [ ] then "This module has no [dedicated maintainers](../../modules.md#maintainers)." else "This module is maintained by ${renderedMaintainers}."; in lib.concatLines [ mainText "## Module information" maintainersText ]; # 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 = let path = "${inputs.self}/docs/src/options/platforms/${platform}.md"; # This doesn't count as IFD because ${inputs.self} is a flake input mainText = if builtins.pathExists path then builtins.readFile path else '' # ${platform.name} > [!NOTE] > 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. ''; in mainText; # 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 between the HTML tags, it must be surrounded by blank lines: # see https://spec.commonmark.org/0.31.2/#html-blocks. 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 [ "