Skip to content

Commit

Permalink
Merge pull request #139 from siraben/flake
Browse files Browse the repository at this point in the history
Add Nix flake
  • Loading branch information
gares authored Dec 25, 2021
2 parents 75285ed + b35c09c commit 1eb6614
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 46 deletions.
22 changes: 10 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,25 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out code base
- name: 'Checkout codebase'
if: github.event_name == 'push'
uses: actions/checkout@v2.3.1
uses: actions/checkout@v2.4.0
with:
fetch-depth: 0

- name: Check out code base
- name: 'Checkout codebase'
if: github.event_name == 'pull_request'
uses: actions/checkout@v2.3.1
uses: actions/checkout@v2.4.0
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

- uses: cachix/install-nix-action@v12
with:
nix_path: nixpkgs=channel:nixos-unstable
- run: NIXPKGS_ALLOW_UNFREE=1 nix-build
- name: "Copy book"
run: "cp result/share/book.pdf ."
- name: "Upload artifact to GitHub"
uses: actions/upload-artifact@v2
- uses: cachix/install-nix-action@v14
- run: NIXPKGS_ALLOW_UNFREE=1 nix --experimental-features 'nix-command flakes' build -L --impure
- name: 'Copy book'
run: cp result/share/book.pdf .
- name: 'Upload artifact to GitHub'
uses: actions/upload-artifact@v2.2.4
with:
name: book.pdf
path: book.pdf
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
**/#*#
tex/gitrev
.DS_Store

result
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# This is the "Mathematical Components" book.
[![build](https://github.com/math-comp/mcb/actions/workflows/build.yml/badge.svg)](https://github.com/math-comp/mcb/actions/workflows/build.yml)

To build the book using Nix, run `nix-build`. Alternatively you may
fetch the latest artifact produced by the CI for the master branch
## Building
To build the book using Nix, run
```ShellSession
# without flakes, check out the repo first
$ NIXPKGS_ALLOW_UNFREE=1 nix-build
# with flakes
$ NIXPKGS_ALLOW_UNFREE=1 nix build github:math-comp/mcb --impure
```

Alternatively you may fetch the latest artifact produced by the CI for
the master branch
[here](https://github.com/math-comp/mcb/actions?query=branch%3Amaster).

The `tex/` directory contains the sources. TexLive 2014 is
The `tex/` directory contains the sources. TexLive 2014, 2021 is
known to work.

The `coq/` directory contains snippets corresponding to the chapters
Expand Down
39 changes: 9 additions & 30 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
with import <nixpkgs> {};

stdenv.mkDerivation rec {
name = "math-comp-book";
version = "master";
src = ./.;

nativeBuildInputs = [ git texlive.combined.scheme-full ];

buildPhase = ''
cd tex
make
biber main
make
make
'';

installPhase = ''
mkdir -p $out/share
cp book.pdf $out/share
'';

meta = with lib; {
description = "Mathematical components book";
homepage = "https://github.com/math-comp/mcb";
license = lib.licenses.cc-by-nc-40;
maintainers = with maintainers; [ siraben ];
platforms = platforms.all;
};
}
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash; }
) {
src = ./.;
}).defaultNix
60 changes: 60 additions & 0 deletions flake.lock

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

46 changes: 46 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
description = "Mathematical Components (the book)";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};

outputs = { self, nixpkgs, utils, ... }:
utils.lib.eachDefaultSystem (system:
with import nixpkgs { inherit system; }; {
defaultPackage = stdenv.mkDerivation {
name = "math-comp-book";
version = "master";
src = ./.;

nativeBuildInputs = [ git texlive.combined.scheme-full ];

buildPhase = ''
cd tex
make
biber main
make
make
'';

installPhase = ''
mkdir -p $out/share
cp book.pdf $out/share
'';

meta = with lib; {
description = "Mathematical components book";
homepage = "https://github.com/math-comp/mcb";
license = lib.licenses.cc-by-nc-40;
maintainers = with maintainers; [ siraben ];
platforms = platforms.all;
};
};
}
);
}

0 comments on commit 1eb6614

Please sign in to comment.