diff --git a/.gitignore b/.gitignore index e5a60b4..28ed2ea 100644 --- a/.gitignore +++ b/.gitignore @@ -385,3 +385,6 @@ svg-inkscape/ .xamples algotex-ctan.zip algotex.tds.zip + +# nix +result diff --git a/flake.lock b/flake.lock index ad709eb..7de1333 100644 --- a/flake.lock +++ b/flake.lock @@ -2,21 +2,36 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1697915759, - "narHash": "sha256-WyMj5jGcecD+KC8gEs+wFth1J1wjisZf8kVZH13f1Zo=", - "owner": "NixOS", + "lastModified": 1778124196, + "narHash": "sha256-pYEytCNic/czazbV9r3tbQ6BZzqRBg/41x2dIC5ymOo=", + "owner": "nixos", "repo": "nixpkgs", - "rev": "51d906d2341c9e866e48c2efcaac0f2d70bfd43e", + "rev": "68a8af93ff4297686cb68880845e61e5e2e41d92", "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" } }, "root": { "inputs": { - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "tuda-pdf": "tuda-pdf" + } + }, + "tuda-pdf": { + "flake": false, + "locked": { + "narHash": "sha256-CCOWBx10m9fRBLbpEuqAAf7AGLo01p1LEU5fOWyqwdQ=", + "type": "file", + "url": "https://www.tu-darmstadt.de/media/medien_stabsstelle_km/services/medien_cd/das_bild_der_tu_darmstadt.pdf" + }, + "original": { + "type": "file", + "url": "https://www.tu-darmstadt.de/media/medien_stabsstelle_km/services/medien_cd/das_bild_der_tu_darmstadt.pdf" } } }, diff --git a/flake.nix b/flake.nix index 25a28bb..9dbafd9 100644 --- a/flake.nix +++ b/flake.nix @@ -1,59 +1,79 @@ { description = "AlgoTeX flake"; - outputs = { self, nixpkgs, }: + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixpkgs-unstable"; + tuda-pdf = { + url = "https://www.tu-darmstadt.de/media/medien_stabsstelle_km/services/medien_cd/das_bild_der_tu_darmstadt.pdf"; + flake = false; + }; + }; + + outputs = + { + self, + nixpkgs, + tuda-pdf, + }: let system = "x86_64-linux"; - pkgs = import nixpkgs { inherit system; }; - algotex = with pkgs; - stdenvNoCC.mkDerivation (finalAttrs: { + pkgs = nixpkgs.legacyPackages.${system}; + in + { + # minimal example shell for using algotex + devShells.${system}.default = pkgs.mkShell { + buildInputs = [ + pkgs.python313Packages.pygments + self.packages.${system}.latex_with_algotex + ]; + }; + + packages.${system} = { + # algotex and logo only + algotex = pkgs.stdenvNoCC.mkDerivation (finalAttrs: { name = "algotex"; - src = fetchFromGitHub { - owner = "tudalgo"; - repo = "AlgoTeX"; - rev = "5f0d8bd394bba5b04eef0d11614b3cadd315f1c8"; - hash = "sha256-hpuPeK1xj62xveMBh8X1NvRKgtRTSUBZk5eOPixxIpY="; - }; + src = ./.; passthru = { pkgs = [ finalAttrs.finalPackage ]; tlType = "run"; - tlDeps = with texlive; [ latex ]; + tlDeps = with pkgs.texlive; [ latex ]; }; - buildInputs = [ librsvg ]; + nativeBuildInputs = with pkgs; [ + inkscape + librsvg + ]; installPhase = '' - mkdir -p $out/tex/latex/algotex - cp -t $out/tex/latex/algotex/ $src/tex/* - cp $out/tex/latex/algotex/FOPBot.sty $out/tex/latex/algotex/fopbot.sty - - mkdir -p $out/tex/latex/local - rsvg-convert -f pdf -o $out/tex/latex/local/tuda_logo.pdf ${ - builtins.fetchurl { - url = - "https://upload.wikimedia.org/wikipedia/de/2/24/TU_Darmstadt_Logo.svg"; - sha256 = - "sha256:0wb2ygg0wzd2ajdzv847xp1qxkx4m1j64p1gdrq4r05klbrddbwl"; - } - } + runHook preInstall + + # copy algotex files + algotex_path=$out/tex/latex/algotex + mkdir -p $algotex_path + cp $src/tex/* $algotex_path/ + + # build tuda logo + logo_path=$out/tex/latex/local + mkdir -p $logo_path + cp ${tuda-pdf} tuda.pdf + + # see https://github.com/tudalgo/AlgoTeX/commit/ce0e2c032d3067070ef07bd8c84520f8209e1997 + inkscape tuda.pdf --export-filename=p1_i.svg --export-dpi=3000 --pages=1 + sed -i 's/icc-color([^)]*)//g' p1_i.svg + sed -i 's/#000000/#1d1d1bff/g' p1_i.svg + rsvg-convert -f pdf -o $logo_path/tuda_logo.pdf p1_i.svg --export-id=g20 + + runHook postInstall ''; + dontConfigure = true; + dontBuild = true; }); - patched-latex = with pkgs.texlive; - combine { - inherit scheme-full; - inherit algotex; - }; - in { - devShells.${system}.default = with pkgs; - mkShell { - buildInputs = [ - python311Packages.pygments - patched-latex - pre-commit - python310Packages.editorconfig - ]; - shellHook = '' - pre-commit install - ''; + + # full texlive distribution with algotex and the logo file + latex_with_algotex = pkgs.texlive.combine { + inherit (pkgs.texlive) scheme-full; + inherit (self.packages.${system}) algotex; }; - packages.${system}.default = patched-latex; + + default = self.packages.${system}.latex_with_algotex; + }; }; }