Skip to content

Commit

Permalink
Added the doc library
Browse files Browse the repository at this point in the history
  • Loading branch information
HU90m committed Jan 24, 2024
1 parent c6a7b29 commit 785de3d
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ Files: flake.lock
pkgs/python_ot/poetry.lock
pkgs/verilator/fix.patch
README.md
**/README.md
Copyright: lowRISC contributors
License: MIT
5 changes: 4 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
...
} @ inputs: let
no_system_outputs = {
lib.poetryOverrides = import ./lib/poetryOverrides.nix;
lib = {
poetryOverrides = import ./lib/poetryOverrides.nix;
doc = import ./lib/doc.nix;
};
};

all_system_outputs = flake-utils.lib.eachDefaultSystem (system: let
Expand Down
30 changes: 30 additions & 0 deletions lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# lowRISC Nix Libraries

## The Documentation Library

The `doc` library contains `buildMdbookSite`, which is a helper function for creating mdBook site builds.
An example of it's use is below.

```nix
let
fs = pkgs.lib.fileset;
in {
docs_build = doc.buildMdbookSite {
pname = "documentation";
version = "0.0.1";
nativeBuildInputs = [pkgs.python311];
src = fs.toSource {
root = ./.;
fileset = fs.unions [
(doc.standardMdbookFileset ./.)
./util/mdbook
./util/mdbook_wavejson.py
];
};
};
}
```

*Note: `pkgs.mdbook` is not required in nativeBuildInputs.*

`standardMdbookFileset` and `hasExts` are also provided to further help in creating derivations.
33 changes: 33 additions & 0 deletions lib/doc.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright lowRISC Contributors.
# Licensed under the MIT License, see LICENSE for details.
# SPDX-License-Identifier: MIT
{pkgs}: let
fs = pkgs.lib.fileset;
# Returns true if a file has an extension in the array `exts`.
hasExts = exts: file: builtins.any file.hasExt exts;
in {
inherit hasExts;

standardMdbookFileset = root:
fs.unions [
(root + /book.toml)
(fs.fileFilter (hasExts ["md" "svg" "png"]) root)
];

# A helper function to create mdBook site builds.
buildMdbookSite = {
pname,
version,
src,
...
} @ inputs:
pkgs.stdenv.mkDerivation ({
dontFixup = true;
buildPhase = "${pkgs.mdbook}/bin/mdbook build";
installPhase = ''
mkdir $out
cp -r book/* $out
'';
}
// inputs);
}

0 comments on commit 785de3d

Please sign in to comment.