Skip to content

Commit

Permalink
Add Nix
Browse files Browse the repository at this point in the history
I am not a Nix expert, but the change should be simple enough for me to
be able to maintain it.
  • Loading branch information
meator committed Aug 18, 2024
1 parent daa422a commit bf74f1f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
25 changes: 11 additions & 14 deletions .github/workflows/mdbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: classabbyamp/treeless-checkout-action@v1
- name: Download latest mdbook, mdbook-toc and mdbook-admonish
run: |
MDBOOK_VERSION="$(basename $(curl -Ls -o /dev/null -w %{url_effective} https://github.com/rust-lang/mdBook/releases/latest))"
wget -q -O- "https://github.com/rust-lang/mdBook/releases/download/${MDBOOK_VERSION}/mdbook-${MDBOOK_VERSION}-x86_64-unknown-linux-gnu.tar.gz" | tar -xzf - -C .
MDBOOK_TOC_VERSION="$(basename $(curl -Ls -o /dev/null -w %{url_effective} https://github.com/badboy/mdbook-toc/releases/latest))"
wget -q -O- "https://github.com/badboy/mdbook-toc/releases/download/${MDBOOK_TOC_VERSION}/mdbook-toc-${MDBOOK_TOC_VERSION}-x86_64-unknown-linux-gnu.tar.gz" | tar -xzf - -C .
MDBOOK_ADMONISH_VERSION="$(basename $(curl -Ls -o /dev/null -w %{url_effective} https://github.com/tommilligan/mdbook-admonish/releases/latest))"
wget -q -O- "https://github.com/tommilligan/mdbook-admonish/releases/download/${MDBOOK_ADMONISH_VERSION}/mdbook-admonish-${MDBOOK_ADMONISH_VERSION}-x86_64-unknown-linux-gnu.tar.gz" | tar -xzf - -C .
- name: Setup Nix
uses: nixbuild/nix-quick-install-action@v28
- name: Restore and cache Nix store
uses: nix-community/cache-nix-action@v5
# See https://github.com/nix-community/cache-nix-action/blob/main/README.md#example-steps
# Cache purging is delegated to GitHub (this means a maximum 10G of data accessed
# less than a week ago).
with:
primary-key: nix-${{ hashFiles('**/*.nix') }}
restore-prefixes-first-match: nix-
- name: Setup Pages
id: pages
uses: actions/configure-pages@v4
- name: Build with mdBook
run: PATH="$GITHUB_WORKSPACE:$PATH" ./book.sh build
run: ./nix-book.sh build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ currently packaged on Void Linux. You can download its executable in
extract the appropriate archive and put the executable into a directory in
`$PATH`.

#### Building with Nix
Alternatively, [nix](https://github.com/NixOS/nix) can be used to automatically
(and reproducibly) download dependencies. This can be done with `nix-book.sh`,
which is a wrapper around `book.sh` (described below); it behaves the same,
and it accepts the same arguments.

`nix-book.sh` is used in the GitHub workflow which builds the website.

### Build process
You mustn't build this book with raw `mdbook`. This repo provides a `book.sh`
script which handles book building. See `book.sh -h` for more info about the
Expand Down
4 changes: 4 additions & 0 deletions nix-book.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash --pure

exec ./book.sh "$@"
13 changes: 13 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let
nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-24.05";
pkgs = import nixpkgs {};
in

pkgs.mkShellNoCC {
packages = with pkgs; [
bash
mdbook
mdbook-toc
mdbook-admonish
];
}

0 comments on commit bf74f1f

Please sign in to comment.