Skip to content

Commit

Permalink
refactor: nix stack
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Sep 20, 2024
1 parent 9a0c998 commit 054ee23
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 100 deletions.
40 changes: 28 additions & 12 deletions flake.lock

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

66 changes: 32 additions & 34 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
flake = false;
url = "github:typst/packages";
};
pkgs-by-name-for-flake-parts.url = "github:drupol/pkgs-by-name-for-flake-parts";
};

outputs =
Expand All @@ -18,12 +19,11 @@

imports = [
./nix/imports/pkgs.nix
./nix/imports/overlay.nix
./nix/imports/formatter.nix
inputs.pkgs-by-name-for-flake-parts.flakeModule
];

perSystem =
{ pkgs, lib, ... }:
{ pkgs, lib, config, ... }:
let
# Change here to typst-dev if needed
typst = pkgs.nixpkgs-unstable.typst;
Expand All @@ -39,8 +39,22 @@
];
};

typst-wrapper = pkgs.typst-wrapper typst pkgs.typst-packages fontsConf;
typstyle = pkgs.typstyle;
typst-wrapper-factory =
typstDrv: typst-packages: typstFontPaths:
pkgs.writeShellApplication {
name = "typst-wrapper";

runtimeInputs = [
typstDrv
typst-packages
];

text = ''
TYPST_FONT_PATHS=${typstFontPaths} XDG_CACHE_HOME=${typst-packages} ${lib.getExe typstDrv} "$@"
'';
};

typst-wrapper = typst-wrapper-factory typst config.packages.typst-packages fontsConf;

mkBuildDocumentDrv =
documentName:
Expand Down Expand Up @@ -120,37 +134,21 @@
lib.filterAttrs (k: v: (v == "directory")) (builtins.readDir ./src)
)) (d: mkBuildDocumentDrv d);

signPDF = pkgs.writeShellApplication {
name = "sign-pdf";

runtimeInputs = [ pkgs.open-pdf-sign ];

text = ''
open-pdf-sign \
--certificate cert.pem \
--key private-key.pem \
--no-hint \
--timestamp \
--tsa http://timestamp.digicert.com \
--baseline-lt \
--add-page \
--page \
-1 \
--width 19 \
"$@"
'';
};

scriptDrvs = { "sign-pdf" = signPDF; } // lib.foldl' (
a: i:
a
// {
"build-${i}" = mkBuildDocumentScript i;
"watch-${i}" = mkWatchDocumentScript i;
scriptDrvs =
{
"sign-pdf" = config.packages.sign-pdf;
}
) { } (lib.attrNames documentDrvs);
// lib.foldl' (
a: i:
a
// {
"build-${i}" = mkBuildDocumentScript i;
"watch-${i}" = mkWatchDocumentScript i;
}
) { } (lib.attrNames documentDrvs);
in
{
pkgsDirectory = ./nix/pkgs;
packages = documentDrvs;

devShells.default = pkgs.mkShellNoCC {
Expand All @@ -165,7 +163,7 @@
echo "Typst version: ${typst.version}"
echo "Typst bin: ${lib.getExe typst}"
echo "Typst wrapper bin: ${lib.getExe typst-wrapper}"
echo "Typst packages directory: ${pkgs.typst-packages}"
echo "Typst packages directory: ${config.packages.typst-packages}"
echo "Typst fonts directory: ${fontsConf}"
'';

Expand Down
8 changes: 0 additions & 8 deletions nix/imports/formatter.nix

This file was deleted.

9 changes: 0 additions & 9 deletions nix/imports/overlay.nix

This file was deleted.

3 changes: 0 additions & 3 deletions nix/imports/pkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
inherit system;
overlays = [
inputs.typst-dev.overlays.default
inputs.self.overlays.default
(final: prev: { nixpkgs-unstable = import inputs.nixpkgs-unstable { inherit system; }; })
];
config = {
};
};
};
}
17 changes: 0 additions & 17 deletions nix/imports/shell.nix

This file was deleted.

21 changes: 21 additions & 0 deletions nix/pkgs/sign-pdf/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{ pkgs, ... }:
pkgs.writeShellApplication {
name = "sign-pdf";

runtimeInputs = [ pkgs.open-pdf-sign ];

text = ''
open-pdf-sign \
--certificate cert.pem \
--key private-key.pem \
--no-hint \
--timestamp \
--tsa http://timestamp.digicert.com \
--baseline-lt \
--add-page \
--page \
-1 \
--width 19 \
"$@"
'';
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{ stdenvNoCC, src }:
{ stdenvNoCC, inputs }:

stdenvNoCC.mkDerivation {
name = "typst-packages";

inherit src;
src = inputs.typst-packages;

dontBuild = true;

Expand Down
15 changes: 0 additions & 15 deletions nix/pkgs/typst-wrapper.nix

This file was deleted.

0 comments on commit 054ee23

Please sign in to comment.