diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9bef4fe --- /dev/null +++ b/Dockerfile @@ -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 / diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..f146e4c --- /dev/null +++ b/flake.lock @@ -0,0 +1,78 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1728330715, + "narHash": "sha256-xRJ2nPOXb//u1jaBnDP56M7v5ldavjbtR6lfGqSvcKg=", + "owner": "numtide", + "repo": "devshell", + "rev": "dd6b80932022cea34a019e2bb32f6fa9e494dfef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1730504689, + "narHash": "sha256-hgmguH29K2fvs9szpq2r3pz2/8cJd2LPS+b4tfNFCwE=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "506278e768c2a08bec68eb62932193e341f55c90", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1732815325, + "narHash": "sha256-Q3aHcePLiWek5P1hCXQP55DoaHiHkIQPK4F5Ro4l8kI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c7c136a6105863cb34d2f26ae936331467c3cb3c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1730504152, + "narHash": "sha256-lXvH/vOfb4aGYyvFmZK/HlsNsr/0CVWlwYvo2rxJk3s=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/cc2f28000298e1269cea6612cd06ec9979dd5d7f.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/cc2f28000298e1269cea6612cd06ec9979dd5d7f.tar.gz" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..3f514b6 --- /dev/null +++ b/flake.nix @@ -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/ + ''; + }; + }; + }; + }; +} diff --git a/nix/texlive.nix b/nix/texlive.nix new file mode 100644 index 0000000..0ce474b --- /dev/null +++ b/nix/texlive.nix @@ -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