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 294182d
Show file tree
Hide file tree
Showing 4 changed files with 258 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/
'';
};
};
};
};
}
98 changes: 98 additions & 0 deletions nix/texlive.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{ texlive }:
let
texliveBasic = {
inherit (texlive) scheme-basic;
};

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

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

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

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

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

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

texliveBib = {
inherit (texlive)
biblatex
biblatex-ext
siunitx
;
};

texlivePackages =
texliveBasic
// texliveLanguageSupport
// texliveFonts
// texliveMaths
// texliveGraphics
// texliveLayout
// texliveUtilities
// texliveBib;
in
texlive.combine texlivePackages

0 comments on commit 294182d

Please sign in to comment.