Skip to content

Commit

Permalink
Use typix for nactl build
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasmohrin committed Apr 1, 2024
1 parent 50de9c2 commit 68381dc
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 58 deletions.
23 changes: 22 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

129 changes: 72 additions & 57 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
});
}

0 comments on commit 68381dc

Please sign in to comment.