From 85f1c033c4a489e3e38cd1af0c0495b273f2e727 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Sun, 22 Feb 2026 22:30:47 -0600 Subject: Initial commit --- .gitignore | 3 +++ flake.lock | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 19 ++++++++++++++++ module.nix | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ template/flake.nix | 39 ++++++++++++++++++++++++++++++++ 5 files changed, 186 insertions(+) create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 module.nix create mode 100644 template/flake.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f0b3cda --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.direnv +result +template/flake.lock diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..99004ba --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1769996383, + "narHash": "sha256-AnYjnFWgS49RlqX7LrC4uA+sCCDBj0Ry/WOJ5XWAsa0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "57928607ea566b5db3ad13af0e57e921e6b12381", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1769909678, + "narHash": "sha256-cBEymOf4/o3FD5AZnzC3J9hLbiZ+QDT/KDuyHXVJOpM=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "72716169fe93074c333e8d0173151350670b824c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d17aca5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,19 @@ +{ + description = "TeX devShell for flake-parts"; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + systems.url = "github:nix-systems/default"; + }; + + outputs = inputs @ { self, flake-parts, ... }: flake-parts.lib.mkFlake { inherit self inputs; } { + systems = import inputs.systems; + + flake.flakeModules.default = ./module.nix; + + flake.templates.default = { + path = ./template; + description = "TeX-utils default template"; + }; + }; +} diff --git a/module.nix b/module.nix new file mode 100644 index 0000000..8cd81eb --- /dev/null +++ b/module.nix @@ -0,0 +1,65 @@ +{ + lib, + flake-parts-lib, + ... +}: +let + inherit (lib) mkOption mkPackageOption mkEnableOption types; + inherit (flake-parts-lib) mkPerSystemOption; +in { + options.perSystem = mkPerSystemOption ({ config, ... }: { + options = { + texShell = { + scheme = mkPackageOption pkgs "texliveSmall" {}; + extraPackages = mkOption { + type = types.functionTo (types.listOf types.package); + description = "Extra packages to add to the texlive scheme"; + default = _: []; + }; + latexmk = { + enable = mkEnableOption "latexmk"; + rc = mkOption { + type = types.lines; + description = "contents of the .latexmkrc file"; + }; + rcFile = mkOption { + type = types.path; + default = pkgs.writeText "latexmkrc" config.texShell.latexmk.rc; + description = "the .latexmkrc file"; + }; + _wrapper = mkOption { + type = types.functionTo types.package; + readOnly = true; + internal = true; + default = tex: pkgs.symlinkJoin { + inherit (tex) name; + nativeBuildInputs = [ + pkgs.makeWrapper + ]; + paths = [ + tex + ]; + postBuild = '' + wrapProgram $out/bin/latexmk --add-flags "-r" --add-flags "${config.texShell.latexmk.rcFile}" + ''; + }; + }; + }; + }; + }; + + config = { + texShell.extraPackages = mkIf config.texShell.latexmk.enable (ps: [ ps.latexmk ]); + + packages.texShell = let + wrapper = if config.texShell.latexmk.enable then config.texShell.latexmk._wrapper else x: x; + in wrapper (config.texShell.scheme.withPackages config.texShell.scheme.extraPackages); + + devShells.texShell = pkgs.makeShell { + nativeBuildInputs = [ + config.packages.texShell + ]; + }; + }; + }); +} diff --git a/template/flake.nix b/template/flake.nix new file mode 100644 index 0000000..498cda1 --- /dev/null +++ b/template/flake.nix @@ -0,0 +1,39 @@ +{ + description = "TeX project"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs"; + flake-parts.url = "github:hercules-ci/flake-parts"; + tex-shell.url = "git://git.mathematicaster.org/tex-shell"; + systems.url = "github:nix-systems/default"; + }; + + outputs = inputs @ { self, flake-parts, ... }: flake-parts.lib.mkFlake { inherit self inputs; } { + systems = import inputs.systems; + + imports = [ + inputs.tex-shell.flakeModules.default + ]; + + perSystem = { pkgs, config, ... }: { + + texShell = { + scheme = pkgs.texliveSmall; + latexmk = { + enable = true; + rc = /* perl */ '' + $out_dir = '.latex-build'; + $pdf_mode = 1; + $pdflatex = 'pdflatex -interaction=nonstopmode %O %S'; + ''; + }; + }; + + devShells.default = pkgs.mkShell { + inputsFrom = [ + config.devShells.texShell + ]; + }; + }; + }; +} -- cgit v1.2.3