Skip to content

Commit

Permalink
docs: use nuscht search for options
Browse files Browse the repository at this point in the history
  • Loading branch information
getchoo committed Nov 29, 2024
1 parent becc648 commit 18ab3ba
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 116 deletions.
118 changes: 117 additions & 1 deletion dev/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 74 additions & 31 deletions dev/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

# NOTE: This is only to deduplicate inputs
flake-utils = {
url = "github:numtide/flake-utils";
};

nuscht-search = {
url = "github:NuschtOS/search";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};

catppuccin-rolling = {
url = "github:catppuccin/nix";
};

catppuccin-v1 = {
url = "https://flakehub.com/f/catppuccin/nix/1.*.tar.gz";
};

nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-24.05";

home-manager = {
Expand All @@ -19,11 +41,14 @@
outputs =
{
self,
nuscht-search,
nixpkgs,
nixpkgs-stable,
home-manager,
home-manager-stable,
}:
...
}@inputs:

let
systems = [
"x86_64-linux"
Expand All @@ -38,14 +63,30 @@
});

forAllSystems = nixpkgs.lib.genAttrs systems;

# Versions of the modules we want to index in our search
searchVersions = [
{
versionName = "v1";
catppuccin = inputs.catppuccin-v1;
}
{
versionName = "rolling";
catppuccin = inputs.catppuccin-rolling;
}
];

in

{
apps = forAllSystems (
system:

let
pkgs = nixpkgsFor.${system}.unstable;
inherit (pkgs) lib;
in

{
serve = {
type = "app";
Expand All @@ -56,13 +97,15 @@

checks = forAllSystems (
system:

let
pkgs = nixpkgsFor.${system};
inherit (pkgs.unstable) lib;

callUnstable = lib.flip pkgs.unstable.callPackage { inherit home-manager; };
callStable = lib.flip pkgs.stable.callPackage { home-manager = home-manager-stable; };
in

lib.optionalAttrs pkgs.unstable.stdenv.hostPlatform.isDarwin {
darwin-test-unstable = callUnstable ../tests/darwin.nix;
darwin-test-stable = callStable ../tests/darwin.nix;
Expand All @@ -77,43 +120,43 @@

packages = forAllSystems (
system:

let
pkgs = nixpkgsFor.${system}.unstable;
inherit (pkgs) lib;

version = self.shortRev or self.dirtyShortRev or "unknown";
mkOptionDoc = pkgs.callPackage ../docs/options-doc.nix { };
mkSite = pkgs.callPackage ../docs/mk-site.nix { };
packages' = self.packages.${system};
in
{
nixos-doc = mkOptionDoc {
inherit version;
moduleRoot = ../modules/nixos;
mkSearchInstance = pkgs.callPackage ../docs/mk-search.nix {
inherit (nuscht-search.packages.${system}) mkMultiSearch;
};

home-manager-doc = mkOptionDoc {
inherit version;
moduleRoot = ../modules/home-manager;
};
search-instances = lib.listToAttrs (
map (
{ catppuccin, versionName }:
{
name = "search-${versionName}";
value = mkSearchInstance { inherit catppuccin versionName; };
}
) searchVersions
);
in

search-instances
// {
site = mkSite {
pname = "catppuccin-nix-site";
version = self.shortRev or self.dirtyShortRev or "unknown";

src = ../docs;

postPatch = "ln -sf ${inputs.catppuccin-rolling + "/CHANGELOG.md"} src/NEWS.md";

site = mkSite rec {
pname = "catppuccin-nix-website";
inherit version;

src = lib.fileset.toSource {
root = ../.;
fileset = lib.fileset.unions [
../CHANGELOG.md
../docs/src
../docs/book.toml
../docs/theme
];
};
sourceRoot = "${src.name}/docs";

nixosDoc = packages'.nixos-doc;
homeManagerDoc = packages'.home-manager-doc;
postInstall = lib.concatLines (
[ "mkdir -p $out/search" ]
++ lib.mapAttrsToList (
name: value: "ln -s ${value.outPath} $out/${lib.replaceStrings [ "-" ] [ "/" ] name}"
) search-instances
);
};

add-source =
Expand All @@ -133,7 +176,7 @@
chmod 755 $out/bin/add-source
'';

default = packages'.site;
default = self.packages.${system}.site;
}
);
};
Expand Down
25 changes: 25 additions & 0 deletions docs/mk-search.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ mkMultiSearch }:

{ catppuccin, versionName }:

let
urlPrefix = "https://github.com/catppuccin/nix/tree/${catppuccin.rev}/";
in

mkMultiSearch {
title = "catppuccin/nix Option Search";
baseHref = "/search/${versionName}/";

scopes = [
{
name = "NixOS modules";
modules = [ catppuccin.nixosModules.catppuccin ];
inherit urlPrefix;
}
{
name = "home-manager modules";
modules = [ catppuccin.homeManagerModules.catppuccin ];
inherit urlPrefix;
}
];
}
18 changes: 7 additions & 11 deletions docs/mk-site.nix
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
{
lib,
stdenvNoCC,
writeShellApplication,
mdbook,
python3,
writeShellApplication,
}:
{ nixosDoc, homeManagerDoc, ... }@args:

args:

stdenvNoCC.mkDerivation (
finalAttrs:
args
// {
nativeBuildInputs = [ mdbook ];
nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [ mdbook ];

dontPatch = true;
dontConfigure = true;
doCheck = false;

buildPhase = ''
runHook preBuild
ln -s ${nixosDoc} src/options/nixos-options.md
ln -s ${homeManagerDoc} src/options/home-manager-options.md
mdbook build
runHook postBuild
'';

installPhase = ''
runHook preInstall
mv book $out
runHook postInstall
'';

passthru = {
passthru = lib.recursiveUpdate (args.passthru or { }) {
serve = writeShellApplication {
name = "serve";

Expand Down
Loading

0 comments on commit 18ab3ba

Please sign in to comment.