Skip to content

Commit 054ee23

Browse files
committed
refactor: nix stack
1 parent 9a0c998 commit 054ee23

File tree

9 files changed

+83
-100
lines changed

9 files changed

+83
-100
lines changed

flake.lock

Lines changed: 28 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
flake = false;
1010
url = "github:typst/packages";
1111
};
12+
pkgs-by-name-for-flake-parts.url = "github:drupol/pkgs-by-name-for-flake-parts";
1213
};
1314

1415
outputs =
@@ -18,12 +19,11 @@
1819

1920
imports = [
2021
./nix/imports/pkgs.nix
21-
./nix/imports/overlay.nix
22-
./nix/imports/formatter.nix
22+
inputs.pkgs-by-name-for-flake-parts.flakeModule
2323
];
2424

2525
perSystem =
26-
{ pkgs, lib, ... }:
26+
{ pkgs, lib, config, ... }:
2727
let
2828
# Change here to typst-dev if needed
2929
typst = pkgs.nixpkgs-unstable.typst;
@@ -39,8 +39,22 @@
3939
];
4040
};
4141

42-
typst-wrapper = pkgs.typst-wrapper typst pkgs.typst-packages fontsConf;
43-
typstyle = pkgs.typstyle;
42+
typst-wrapper-factory =
43+
typstDrv: typst-packages: typstFontPaths:
44+
pkgs.writeShellApplication {
45+
name = "typst-wrapper";
46+
47+
runtimeInputs = [
48+
typstDrv
49+
typst-packages
50+
];
51+
52+
text = ''
53+
TYPST_FONT_PATHS=${typstFontPaths} XDG_CACHE_HOME=${typst-packages} ${lib.getExe typstDrv} "$@"
54+
'';
55+
};
56+
57+
typst-wrapper = typst-wrapper-factory typst config.packages.typst-packages fontsConf;
4458

4559
mkBuildDocumentDrv =
4660
documentName:
@@ -120,37 +134,21 @@
120134
lib.filterAttrs (k: v: (v == "directory")) (builtins.readDir ./src)
121135
)) (d: mkBuildDocumentDrv d);
122136

123-
signPDF = pkgs.writeShellApplication {
124-
name = "sign-pdf";
125-
126-
runtimeInputs = [ pkgs.open-pdf-sign ];
127-
128-
text = ''
129-
open-pdf-sign \
130-
--certificate cert.pem \
131-
--key private-key.pem \
132-
--no-hint \
133-
--timestamp \
134-
--tsa http://timestamp.digicert.com \
135-
--baseline-lt \
136-
--add-page \
137-
--page \
138-
-1 \
139-
--width 19 \
140-
"$@"
141-
'';
142-
};
143-
144-
scriptDrvs = { "sign-pdf" = signPDF; } // lib.foldl' (
145-
a: i:
146-
a
147-
// {
148-
"build-${i}" = mkBuildDocumentScript i;
149-
"watch-${i}" = mkWatchDocumentScript i;
137+
scriptDrvs =
138+
{
139+
"sign-pdf" = config.packages.sign-pdf;
150140
}
151-
) { } (lib.attrNames documentDrvs);
141+
// lib.foldl' (
142+
a: i:
143+
a
144+
// {
145+
"build-${i}" = mkBuildDocumentScript i;
146+
"watch-${i}" = mkWatchDocumentScript i;
147+
}
148+
) { } (lib.attrNames documentDrvs);
152149
in
153150
{
151+
pkgsDirectory = ./nix/pkgs;
154152
packages = documentDrvs;
155153

156154
devShells.default = pkgs.mkShellNoCC {
@@ -165,7 +163,7 @@
165163
echo "Typst version: ${typst.version}"
166164
echo "Typst bin: ${lib.getExe typst}"
167165
echo "Typst wrapper bin: ${lib.getExe typst-wrapper}"
168-
echo "Typst packages directory: ${pkgs.typst-packages}"
166+
echo "Typst packages directory: ${config.packages.typst-packages}"
169167
echo "Typst fonts directory: ${fontsConf}"
170168
'';
171169

nix/imports/formatter.nix

Lines changed: 0 additions & 8 deletions
This file was deleted.

nix/imports/overlay.nix

Lines changed: 0 additions & 9 deletions
This file was deleted.

nix/imports/pkgs.nix

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77
inherit system;
88
overlays = [
99
inputs.typst-dev.overlays.default
10-
inputs.self.overlays.default
1110
(final: prev: { nixpkgs-unstable = import inputs.nixpkgs-unstable { inherit system; }; })
1211
];
13-
config = {
14-
};
1512
};
1613
};
1714
}

nix/imports/shell.nix

Lines changed: 0 additions & 17 deletions
This file was deleted.

nix/pkgs/sign-pdf/package.nix

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{ pkgs, ... }:
2+
pkgs.writeShellApplication {
3+
name = "sign-pdf";
4+
5+
runtimeInputs = [ pkgs.open-pdf-sign ];
6+
7+
text = ''
8+
open-pdf-sign \
9+
--certificate cert.pem \
10+
--key private-key.pem \
11+
--no-hint \
12+
--timestamp \
13+
--tsa http://timestamp.digicert.com \
14+
--baseline-lt \
15+
--add-page \
16+
--page \
17+
-1 \
18+
--width 19 \
19+
"$@"
20+
'';
21+
}

nix/pkgs/typst-packages.nix renamed to nix/pkgs/typst-packages/package.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
{ stdenvNoCC, src }:
1+
{ stdenvNoCC, inputs }:
22

33
stdenvNoCC.mkDerivation {
44
name = "typst-packages";
55

6-
inherit src;
6+
src = inputs.typst-packages;
77

88
dontBuild = true;
99

nix/pkgs/typst-wrapper.nix

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)