Generate docs (#1)

* feat: Reorganize code

* feat: Generate docs as mdbook

* feat: Add deploy github action

* fix: formatting
This commit is contained in:
Jalil David Salamé Messina 2024-01-14 18:58:08 +01:00 committed by GitHub
parent ca6bf00ad6
commit 63034a2af9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 144 additions and 70 deletions

43
.github/workflows/deploy.yaml vendored Normal file
View file

@ -0,0 +1,43 @@
name: Deploy Documentation
on:
push:
branches: [main]
paths:
- ./.github/workflows/deploy.yaml # this workflow
- ./docs/** # Docs generation code
- ./options.nix # module options
# Nix files
- flake.lock
- flake.nix
jobs:
build-website:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: DeterminateSystems/nix-installer-action@v9
- uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Build documentation
run: nix build .#docs --print-build-logs
- name: Adjust permissions
run: |
chown -R "$(id -u):$(id -g)" ./result
chmod -R a+rwx ./result
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: ./result
deploy:
needs: build
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2

1
docs/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
book

6
docs/book.toml Normal file
View file

@ -0,0 +1,6 @@
[book]
authors = ["Jalil David Salamé Messina"]
language = "en"
multilingual = false
src = "src"
title = "Jalil's NixOS configuration module"

16
docs/default.nix Normal file
View file

@ -0,0 +1,16 @@
{ pkgs, lib, ... }:
let
eval = lib.evalModules { modules = [ ../options.nix ]; };
doc = (pkgs.nixosOptionsDoc { inherit (eval) options; }).optionsCommonMark;
in
pkgs.stdenvNoCC.mkDerivation {
name = "nixos-configuration-book";
src = ./.;
patchPhase = ''
# copy generated options removing the declared by statement
sed '/^\*Declared by:\*$/,/^$/d' <${doc} >> src/options.md
'';
buildPhase = "${pkgs.mdbook}/bin/mdbook build --dest-dir $out";
}

3
docs/src/SUMMARY.md Normal file
View file

@ -0,0 +1,3 @@
# Summary
- [Module Options](./options.md)

3
docs/src/options.md Normal file
View file

@ -0,0 +1,3 @@
# Module Options
Here you will find the module options and their default values (if they have any).

View file

@ -15,22 +15,25 @@
# Flake outputs that other flakes can use
outputs = { flake-schemas, nixpkgs, stylix, ... }:
let
inherit (nixpkgs) lib;
# Helpers for producing system-specific outputs
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
pkgs = import nixpkgs { inherit system; };
});
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f { pkgs = import nixpkgs { inherit system; }; });
# Module documentation
doc = forEachSupportedSystem ({ pkgs }: { doc = import ./docs { inherit pkgs lib; }; });
in
{
# Schemas tell Nix about the structure of your flake's outputs
schemas = flake-schemas.schemas;
packages = doc;
# Nix files formatter (run `nix fmt`)
formatter = forEachSupportedSystem ({ pkgs }: pkgs.nixpkgs-fmt);
nixosModules = rec {
default = nixosModule;
nixosModule = import ./configuration { inherit stylix; };
nixosModule = import ./module { inherit stylix; };
};
};
}

View file

@ -1,46 +1,11 @@
{ stylix }: { config, pkgs, lib, ... }:
let
inherit (lib) types;
cfg = config.jconfig;
mkDisableOption = option: lib.mkOption {
description = lib.mdDoc "Whether to enable ${option}.";
type = types.bool;
default = true;
example = false;
};
in
{
imports = [ ./gui ] ++ lib.optional (cfg.enable && cfg.styling.enable) stylix.homeManagerModules.stylix;
imports = [ ./gui ] ++ lib.optional (cfg.enable && cfg.styling.enable) stylix.nixosModules.stylix;
options.jconfig = lib.mkOption {
description = lib.mdDoc "Jalil's default NixOS configuration.";
type = types.submodule {
options.enable = lib.mkEnableOption "jalil's default configuration.";
options.styling = lib.mkOption {
description = "Jalil's styling options";
type = types.submodule {
options.enable = mkDisableOption "jalil's default styling";
options.wallpaper = lib.mkOption {
description = "The wallpaper to use.";
type = types.str;
default = builtins.fetchurl {
url = "https://raw.githubusercontent.com/lunik1/nixos-logo-gruvbox-wallpaper/d4937c424fad79c1136a904599ba689fcf8d0fad/png/gruvbox-dark-rainbow.png";
sha256 = "036gqhbf6s5ddgvfbgn6iqbzgizssyf7820m5815b2gd748jw8zc";
};
};
options.bootLogo = lib.mkOption {
description = "The logo used by plymouth at boot.";
type = types.str;
# http://xenia-linux-site.glitch.me/images/cathodegaytube-splash.png
default = builtins.fetchurl {
url = "https://efimero.github.io/xenia-images/cathodegaytube-splash.png";
sha256 = "qKugUfdRNvMwSNah+YmMepY3Nj6mWlKFh7jlGlAQDo8=";
};
};
};
};
};
};
options = import ../options.nix;
config = lib.optionalAttrs cfg.enable {
boot.plymouth.enable = cfg.styling.enable;

View file

@ -1,37 +1,9 @@
{ config, lib, pkgs, ... }:
let
inherit (lib) types;
cfg = config.jconfig.gui;
enable = config.jconfig.enable && cfg.enable;
# Like lib.mkEnableOption but default to true
mkDisableOption = option: lib.mkOption {
description = lib.mdDoc "Whether to enable ${option}.";
type = types.bool;
default = true;
example = false;
};
in
{
options.jhome.gui = lib.mkOption {
description = lib.mdDoc "Jalil's default configuration for a NixOS gui.";
type = types.submodule {
options.enable = lib.mkEnableOption "jalil's default gui configuration.";
# Fix for using Xinput mode on 8bitdo Ultimate C controller
# Inspired by https://aur.archlinux.org/packages/8bitdo-ultimate-controller-udev
# Adapted from: https://gist.github.com/interdependence/28452fbfbe692986934fbe1e54c920d4
options."8bitdoFix" = mkDisableOption "a fix for 8bitdo controllers";
options.steamHardwareSupport = mkDisableOption "steam hardware support";
options.ydotool = lib.mkOption {
description = lib.mdDoc "Jalil's default ydotool configuration.";
type = types.submodule {
options.enable = mkDisableOption "ydotool";
options.autoStart = mkDisableOption "autostarting ydotool at login";
};
};
};
};
config = lib.optionalAttrs enable
config = lib.optionalAttrs (config.jconfig.enable && cfg.enable)
{
environment.systemPackages = [
pkgs.gnome.adwaita-icon-theme

62
options.nix Normal file
View file

@ -0,0 +1,62 @@
{ lib, ... }:
let
inherit (lib) types;
# Like mkEnableOption but defaults to true
mkDisableOption = option: lib.mkOption {
description = lib.mdDoc "Whether to enable ${option}.";
type = types.bool;
default = true;
example = false;
};
in
{
options.jconfig = lib.mkOption {
description = lib.mdDoc "Jalil's default NixOS configuration.";
type = types.submodule {
options = {
enable = lib.mkEnableOption "jalil's default configuration.";
gui = lib.mkOption {
description = lib.mdDoc "Jalil's default configuration for a NixOS gui.";
type = types.submodule {
options.enable = lib.mkEnableOption "jalil's default gui configuration.";
# Fix for using Xinput mode on 8bitdo Ultimate C controller
# Inspired by https://aur.archlinux.org/packages/8bitdo-ultimate-controller-udev
# Adapted from: https://gist.github.com/interdependence/28452fbfbe692986934fbe1e54c920d4
options."8bitdoFix" = mkDisableOption "a fix for 8bitdo controllers";
options.steamHardwareSupport = mkDisableOption "steam hardware support";
options.ydotool = lib.mkOption {
description = lib.mdDoc "Jalil's default ydotool configuration.";
type = types.submodule {
options.enable = mkDisableOption "ydotool";
options.autoStart = mkDisableOption "autostarting ydotool at login";
};
};
};
};
styling = lib.mkOption {
description = "Jalil's styling options";
type = types.submodule {
options.enable = mkDisableOption "jalil's default styling";
options.wallpaper = lib.mkOption {
description = "The wallpaper to use.";
type = types.str;
default = builtins.fetchurl {
url = "https://raw.githubusercontent.com/lunik1/nixos-logo-gruvbox-wallpaper/d4937c424fad79c1136a904599ba689fcf8d0fad/png/gruvbox-dark-rainbow.png";
sha256 = "036gqhbf6s5ddgvfbgn6iqbzgizssyf7820m5815b2gd748jw8zc";
};
};
options.bootLogo = lib.mkOption {
description = "The logo used by plymouth at boot.";
type = types.str;
# http://xenia-linux-site.glitch.me/images/cathodegaytube-splash.png
default = builtins.fetchurl {
url = "https://efimero.github.io/xenia-images/cathodegaytube-splash.png";
sha256 = "qKugUfdRNvMwSNah+YmMepY3Nj6mWlKFh7jlGlAQDo8=";
};
};
};
};
};
};
};
}