diff options
| -rw-r--r-- | .envrc | 1 | ||||
| -rw-r--r-- | flake.lock | 53 | ||||
| -rw-r--r-- | flake.nix | 43 | ||||
| -rw-r--r-- | module.nix | 114 | ||||
| -rw-r--r-- | template/flake.nix | 44 |
5 files changed, 170 insertions, 85 deletions
@@ -0,0 +1 @@ +use flake . @@ -18,6 +18,21 @@ "type": "github" } }, + "nixpkgs": { + "locked": { + "lastModified": 1771817828, + "narHash": "sha256-G+UqAH3kbz9Ux7uM0+iazOBxoX4DVy9zJzTbDx+OXEs=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "56d662f5e3fdfaf7e87f96b9000d0aec012f13ff", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs-lib": { "locked": { "lastModified": 1769909678, @@ -33,10 +48,28 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1770107345, + "narHash": "sha256-tbS0Ebx2PiA1FRW8mt8oejR0qMXmziJmPaU1d4kYY9g=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "4533d9293756b63904b7238acb84ac8fe4c8c2c4", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "flake-parts": "flake-parts", - "systems": "systems" + "nixpkgs": "nixpkgs", + "systems": "systems", + "treefmt-nix": "treefmt-nix" } }, "systems": { @@ -53,6 +86,24 @@ "repo": "default", "type": "github" } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1770228511, + "narHash": "sha256-wQ6NJSuFqAEmIg2VMnLdCnUc0b7vslUohqqGGD+Fyxk=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "337a4fe074be1042a35086f15481d763b8ddc0e7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", @@ -2,18 +2,47 @@ description = "TeX devShell for flake-parts"; inputs = { + nixpkgs.url = "github:nixos/nixpkgs"; flake-parts.url = "github:hercules-ci/flake-parts"; + treefmt-nix.url = "github:numtide/treefmt-nix"; systems.url = "github:nix-systems/default"; }; - outputs = inputs @ { self, flake-parts, ... }: flake-parts.lib.mkFlake { inherit self inputs; } { - systems = import inputs.systems; + outputs = + inputs@{ self, flake-parts, ... }: + flake-parts.lib.mkFlake { inherit self inputs; } { + systems = import inputs.systems; - flake.flakeModules.default = ./module.nix; + imports = [ inputs.treefmt-nix.flakeModule ]; - flake.templates.default = { - path = ./template; - description = "TeX-utils default template"; + flake.flakeModules.default = ./module.nix; + + flake.templates.default = { + path = ./template; + description = "TeX-utils default template"; + }; + + perSystem = + { config, pkgs, ... }: + { + treefmt = { + programs = { + nixfmt = { + enable = true; + strict = true; + }; + }; + }; + + devShells.default = pkgs.mkShellNoCC { + inputsFrom = [ config.treefmt.build.devShell ]; + nativeBuildInputs = with pkgs; [ + nixd + statix + deadnix + ]; + }; + + }; }; - }; } @@ -1,65 +1,71 @@ -{ - lib, - flake-parts-lib, - ... -}: +{ lib, flake-parts-lib, ... }: let - inherit (lib) mkIf mkOption mkPackageOption mkEnableOption types; + inherit (lib) + mkIf + 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"; +in +{ + options.perSystem = mkPerSystemOption ( + { config, pkgs, ... }: + { + 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 = _: [ ]; }; - rcFile = mkOption { - type = types.path; - default = pkgs.writeText "latexmkrc" config.texShell.latexmk.rc; - description = "the .latexmkrc file"; + 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}" + ''; + }; + }; }; - _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}" - ''; + build = { + package = mkOption { + type = types.package; + readOnly = true; + default = + let + wrapper = if config.texShell.latexmk.enable then config.texShell.latexmk._wrapper else x: x; + in + wrapper (config.texShell.scheme.withPackages config.texShell.extraPackages); }; + devShell = pkgs.mkShellNoCC { nativeBuildInputs = [ config.texShell.build.package ]; }; }; }; }; - }; - - 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 - ]; + config = { + texShell.extraPackages = mkIf config.texShell.latexmk.enable (ps: [ ps.latexmk ]); }; - }; - }); + } + ); } diff --git a/template/flake.nix b/template/flake.nix index 498cda1..59878c1 100644 --- a/template/flake.nix +++ b/template/flake.nix @@ -8,32 +8,30 @@ systems.url = "github:nix-systems/default"; }; - outputs = inputs @ { self, flake-parts, ... }: flake-parts.lib.mkFlake { inherit self inputs; } { - systems = import inputs.systems; + outputs = + inputs@{ self, flake-parts, ... }: + flake-parts.lib.mkFlake { inherit self inputs; } { + systems = import inputs.systems; - imports = [ - inputs.tex-shell.flakeModules.default - ]; + imports = [ inputs.tex-shell.flakeModules.default ]; - perSystem = { pkgs, config, ... }: { + 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'; - ''; - }; - }; + 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 - ]; - }; + devShells.default = pkgs.mkShellNoCC { inputsFrom = [ config.texShell.build.devShell ]; }; + }; }; - }; } |
