Skip to content

Commit e026202

Browse files
committed
Add flake.nix with development environment & CI
This makes it easy to onboard new contributors, as flake.nix provides the fully configured development environment, package definition, and continuous integration: - development environment: nix develop - package build: nix build - package install: nix profile install - testing: nix flake check
1 parent 14df74a commit e026202

File tree

5 files changed

+173
-0
lines changed

5 files changed

+173
-0
lines changed

.github/workflows/nix-build.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: "Nix: build and check"
2+
on:
3+
pull_request:
4+
push:
5+
paths-ignore:
6+
- '**.md'
7+
jobs:
8+
nix:
9+
strategy:
10+
matrix:
11+
os: [ubuntu-latest, macos-latest]
12+
runs-on: ${{ matrix.os }}
13+
env:
14+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: cachix/install-nix-action@v25
18+
with:
19+
nix_path: nixpkgs=channel:nixpkgs-unstable
20+
install_url: https://releases.nixos.org/nix/nix-2.18.1/install
21+
extra_nix_config: |
22+
experimental-features = nix-command flakes
23+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
24+
- uses: DeterminateSystems/magic-nix-cache-action@v2
25+
- run: nix flake check --print-build-logs --show-trace

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
/tests/00*00-latex-*.fmt
66
/tests/*-plain-*.fmt
77
/tests/xenia/paper.pdf
8+
9+
.direnv
10+
.envrc

docs/src/howto/build-tectonic/index.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ binary will save you time and, possibly, headaches.
1414

1515
[install]: ../installation/index.md
1616

17+
If you use the [Nix] package manager, we provide a community maintained
18+
`flake.nix` with the package definition and a fully configured development
19+
environment. Please refer to the [Using Nix](#using-nix) section for more
20+
instructions.
21+
22+
[Nix]: https://nixos.org/
1723

1824
## Basic Prerequisites
1925

@@ -173,3 +179,23 @@ environment variables are set up properly. Read [The Cargo Book][cargo-book] for
173179
vastly more information about where you can go from there.
174180

175181
[cargo-book]: https://doc.rust-lang.org/cargo/index.html
182+
183+
## Using Nix
184+
185+
If you have a working Nix installation [configured] with the experimental
186+
features `flakes` and `nix-command`, you can easily pull in the necessary
187+
dependencies with the following commands at the project root:
188+
189+
- `nix develop` to enter a sub-shell with the development environments
190+
- `nix build` for a reproducible build of the tectonic package
191+
- `nix profile install` to install the package in your local nix profile
192+
193+
The package definition is inherited from the community maintained repository
194+
[nixpkgs], with local overrides defined in `flake.nix` at the root of
195+
Tectonic's source repo. The nixpkgs definition also takes care of some
196+
packaging related issues, such as bundling with the correct version of `biber`
197+
to avoid [incompatibilities][biber-mismatch].
198+
199+
[configured]: https://nixos.org/manual/nix/stable/command-ref/conf-file#conf-experimental-features
200+
[nixpkgs]: https://github.com/NixOS/nixpkgs
201+
[biber-mismatch]: https://github.com/tectonic-typesetting/tectonic/issues/893

flake.lock

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
description = "Tectonic, a modernized TeX/LaTeX engine";
3+
4+
outputs = { self, nixpkgs }:
5+
let
6+
inherit (nixpkgs) lib;
7+
supportedSystems = [
8+
"aarch64-linux"
9+
"aarch64-darwin"
10+
"i686-linux"
11+
"x86_64-darwin"
12+
"x86_64-linux"
13+
];
14+
foreachSystem = f: lib.genAttrs supportedSystems (system: f {
15+
pkgs = nixpkgs.legacyPackages.${system};
16+
/** final packages set (of a given system) provided in this flake */
17+
final = self.packages.${system};
18+
});
19+
addCargoFeatures = x: lib.unique (x ++ [
20+
/** currently nix flake does not work well with git submodules, so we
21+
ensure that the nixpkgs provided harfbuzz is used instead. */
22+
"external-harfbuzz"
23+
]);
24+
in
25+
{
26+
packages = foreachSystem ({ pkgs, final }: {
27+
28+
/** package definition from nixpkgs, with local overrides */
29+
tectonic-unwrapped = pkgs.tectonic-unwrapped.overrideAttrs (
30+
{ meta, cargoBuildFeatures, cargoCheckFeatures, ... }: {
31+
name = "tectonic";
32+
src = ./.;
33+
cargoDeps = pkgs.rustPlatform.importCargoLock {
34+
lockFile = ./Cargo.lock;
35+
};
36+
cargoBuildFeatures = addCargoFeatures cargoBuildFeatures;
37+
cargoCheckFeatures = addCargoFeatures cargoCheckFeatures;
38+
39+
/*
40+
For `flake.nix` contributors: put additional overrides here.
41+
If the changes are also applicable to the `tectonic` package
42+
in nixpkgs, consider first improving the definition there,
43+
and then update the `flake.lock` here.
44+
*/
45+
46+
meta = {
47+
# to correctly generate meta.position for back trace:
48+
inherit (meta) description;
49+
50+
# maintainers for the local overrides:
51+
maintainers = with lib.maintainers; [ bryango ];
52+
};
53+
}
54+
);
55+
56+
/** a version of biber that works with the current tectonic bundle */
57+
inherit (pkgs) biber-for-tectonic;
58+
59+
/** tectonic wrapped with the correct version of biber; this provides
60+
a partial fix for issue #893. */
61+
tectonic = pkgs.tectonic.override {
62+
inherit (final)
63+
tectonic-unwrapped
64+
biber-for-tectonic;
65+
};
66+
67+
/** the default package to build & install */
68+
default = final.tectonic;
69+
});
70+
71+
devShells = foreachSystem ({ pkgs, final }: {
72+
default = final.tectonic-unwrapped.overrideAttrs (prev: {
73+
# for developments, e.g. symbol lookup in std library
74+
env.RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
75+
});
76+
});
77+
78+
checks = foreachSystem ({ pkgs, final }:
79+
let
80+
tectonic-unwrapped =
81+
final.tectonic-unwrapped.overrideAttrs (prevAttrs: {
82+
preCheck = prevAttrs.preCheck or "" + ''
83+
export RUST_BACKTRACE=1
84+
'';
85+
});
86+
in
87+
{
88+
inherit tectonic-unwrapped;
89+
tectonic = final.tectonic.override {
90+
inherit tectonic-unwrapped;
91+
};
92+
});
93+
};
94+
}

0 commit comments

Comments
 (0)