Skip to content

Commit

Permalink
Build using nix
Browse files Browse the repository at this point in the history
Adds flake.nix and a Dockerfile using it
to either build locally using [nix](https://nixos.org)
or using docker, which essentially downloads
nixos and runs the same build process. The download
size is much smaller than the full texlive as
only needed packages are downloaded. They are defined
in nix/texlive.nix and should be enough to install
even outside of nix environment.

This also adds a devshell that you can enter using
`nix develop` to get an environment with texlive with
needed packages
  • Loading branch information
WeetHet committed Nov 28, 2024
1 parent 654ca97 commit 46304e2
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM nixos/nix:latest

WORKDIR /build
COPY . .

RUN echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf

RUN nix build .#astro-notebook

FROM scratch
COPY --from=0 /buildresult/astro-notebook.pdf /
78 changes: 78 additions & 0 deletions flake.lock

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

71 changes: 71 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-parts.url = "github:hercules-ci/flake-parts";
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
inputs@{
flake-parts,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
imports = [
inputs.devshell.flakeModule
];
perSystem =
{ config, pkgs, ... }:
let
texlive = pkgs.callPackage ./nix/texlive.nix { };
in
{
devshells.default = {
packages = [
texlive
];
commands = [
{
help = "Build the notebook PDF using LaTeX";
name = "build-notebook";
command = ''
mkdir -p tikz/resource
latexmk -pdf -xelatex -shell-escape astro-notebook.tex;
'';
}
];
};

packages = {
default = config.packages.astro-notebook;
astro-notebook = pkgs.stdenv.mkDerivation {
name = "astro-notebook";
src = inputs.self;
buildInputs = [
texlive
];

buildPhase = ''
export XDG_CACHE_HOME="$(mktemp -d)"
mkdir -p tikz/resource
latexmk -pdf -xelatex -shell-escape astro-notebook.tex
'';

installPhase = ''
mkdir -p $out
cp astro-notebook.pdf $out/
'';
};
};
};
};
}
107 changes: 107 additions & 0 deletions nix/texlive.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{ texlive }:
let
# Basic scheme
texliveBasic = {
inherit (texlive) scheme-basic;
};

# Language support
texliveLanguageSupport = {
inherit (texlive) babel babel-russian hyphen-russian;
};

# Fonts
texliveFonts = {
inherit (texlive)
cm-unicode
fontspec
mathspec
jknapltx
was
wasy
starfont
wasysym
wrapfig
textcase
rsfs
collection-fontsrecommended
collection-fontutils
;
};

# Maths
texliveMaths = {
inherit (texlive)
siunitx
amsmath
amsfonts
cancel
mathtools
units
xfrac
;
};

# Graphics and figures
texliveGraphics = {
inherit (texlive)
pdflscape
graphics
pgf
tkz-euclide
tikz-3dplot
spath3
pgfplots
qrcode
;
};

# Document layout
texliveLayout = {
inherit (texlive)
geometry
titlesec
adjustbox
caption
pdfpages
xpatch
enumitem
tocloft
;
};

# Utilities
texliveUtilities = {
inherit (texlive)
xetex
xcolor
xifthen
xurl
hyperref
lipsum
latexmk
ifmtarg
;
};

# Bibliography and units
texliveBib = {
inherit (texlive)
biblatex
biblatex-ext
siunitx
;
};

# Combine all package groups
texlivePackages =
texliveBasic
// texliveLanguageSupport
// texliveFonts
// texliveMaths
// texliveGraphics
// texliveLayout
// texliveUtilities
// texliveBib;
in
texlive.combine texlivePackages

0 comments on commit 46304e2

Please sign in to comment.