diff --git a/flake.lock b/flake.lock index 37e2997..a060853 100644 --- a/flake.lock +++ b/flake.lock @@ -54,7 +54,8 @@ "inputs": { "flake-utils": "flake-utils", "kactl": "kactl", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "typix": "typix" } }, "systems": { @@ -71,6 +72,26 @@ "repo": "default", "type": "github" } + }, + "typix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1711493063, + "narHash": "sha256-8b6iIECLJ8XfgMX1r1/PdVJEMElZ9i/zO3QzArCiu+8=", + "owner": "loqusion", + "repo": "typix", + "rev": "7e6e9a7e160856900532cc04d0dce0dc87cad67d", + "type": "github" + }, + "original": { + "owner": "loqusion", + "repo": "typix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 42b1b02..3bac896 100644 --- a/flake.nix +++ b/flake.nix @@ -8,69 +8,84 @@ url = "github:kth-competitive-programming/kactl"; flake = false; }; + typix = { + url = "github:loqusion/typix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - outputs = inputs@{ self, nixpkgs, flake-utils, ... }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { inherit system; }; - lib = pkgs.lib; - pdfPageCount = file: lib.fileContents (pkgs.runCommand "pdfpages" { } "${pkgs.pdftk}/bin/pdftk ${file} dump_data | grep NumberOfPages | sed 's/[^0-9]*//' > $out"); - kactlDerivation = initialPage: pkgs.stdenvNoCC.mkDerivation { - name = "kactl"; - src = inputs.kactl; - phases = [ "unpackPhase" "patchPhase" "buildPhase" "installPhase" ]; - nativeBuildInputs = with pkgs; [ - python310 - (texlive.combine { - inherit (texlive) scheme-medium enumitem framed tocloft titlesec paralist; - }) - ]; - patches = [ ./kactl.patch ]; - buildPhase = '' - echo '\setcounter{page}{ ${toString initialPage} }' > initial-page.tex - make kactl - ''; - installPhase = "cp kactl.pdf $out"; - }; - - in - rec { - packages = rec { - default = nactl; + outputs = inputs@{ self, nixpkgs, flake-utils, typix, ... }: + flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = import nixpkgs { inherit system; }; + inherit (pkgs) lib; - nactl = pkgs.stdenvNoCC.mkDerivation { - name = "nactl"; - src = ./.; - nativeBuildInputs = [ pkgs.typst ]; - phases = [ "unpackPhase" "buildPhase" ]; - buildPhase = "typst compile --format pdf nactl.typ $out"; + pdfPageCount = file: lib.fileContents (pkgs.runCommand "pdfpages" { } "${pkgs.pdftk}/bin/pdftk ${file} dump_data | grep NumberOfPages | sed 's/[^0-9]*//' > $out"); + kactlDerivation = initialPage: pkgs.stdenvNoCC.mkDerivation { + name = "kactl"; + src = inputs.kactl; + phases = [ "unpackPhase" "patchPhase" "buildPhase" "installPhase" ]; + nativeBuildInputs = with pkgs; [ + python310 + (texlive.combine { + inherit (texlive) scheme-medium enumitem framed tocloft titlesec paralist; + }) + ]; + patches = [ ./kactl.patch ]; + buildPhase = '' + echo '\setcounter{page}{ ${toString initialPage} }' > initial-page.tex + make kactl + ''; + installPhase = "cp kactl.pdf $out"; }; + in + rec { + packages = rec { + default = nactl; - kactl = kactlDerivation 1; - nactl-complete = pkgs.runCommand "nactl-complete" { } "${pkgs.poppler_utils}/bin/pdfunite ${nactl} ${kactlDerivation (lib.strings.toInt (pdfPageCount nactl) + 1)} $out"; - }; + nactl = + let + typixLib = typix.lib.${system}; + in + typixLib.buildTypstProject { + src = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + (lib.fileset.fromSource (typixLib.cleanTypstSource ./.)) + ./assets + ./snippets + ./template.cpp + ./toolbin + ]; + }; + typstSource = "nactl.typ"; + fontPaths = [ "${pkgs.liberation_ttf}/share/fonts/truetype" ]; + }; - devShells = - let - typst-packages = with pkgs; [ typst-lsp typst-fmt ]; - contest-packages = with pkgs; [ - clang-tools_16 - clang_16 - fmt - gdb - gnumake + kactl = kactlDerivation 1; + nactl-complete = pkgs.runCommand "nactl-complete" { } "${pkgs.poppler_utils}/bin/pdfunite ${nactl} ${kactlDerivation (lib.strings.toInt (pdfPageCount nactl) + 1)} $out"; + }; - python310 - pypy310 - ]; + devShells = + let + typst-packages = with pkgs; [ typst-lsp typst-fmt ]; + contest-packages = with pkgs; [ + clang-tools_16 + clang_16 + fmt + gdb + gnumake - in - rec { - nactl = pkgs.mkShell { inputsFrom = [ packages.nactl ]; packages = typst-packages; }; - cpp = pkgs.mkShell { packages = contest-packages; }; - combined = pkgs.mkShell { packages = typst-packages ++ contest-packages; }; - default = combined; - }; - }); + python310 + pypy310 + ]; + in + rec { + nactl = pkgs.mkShell { inputsFrom = [ packages.nactl ]; packages = typst-packages; }; + contest = pkgs.mkShell { packages = contest-packages; }; + combined = pkgs.mkShell { packages = typst-packages ++ contest-packages; }; + default = combined; + }; + }); }