aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--flake.lock60
-rw-r--r--flake.nix19
-rw-r--r--module.nix65
-rw-r--r--template/flake.nix39
5 files changed, 186 insertions, 0 deletions
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
+ ];
+ };
+ };
+ };
+}