-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.nix
82 lines (81 loc) · 2.47 KB
/
lib.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{
pkgs,
inputs,
...
}: let
#inherit (nixpkgs)
inherit (pkgs) lib writeShellApplication linkFarm symlinkJoin; ## We simply call packages when it's in scope, rather then doing a full import
#inherit (nixpkgs) lib;
inherit (builtins) pathExists readDir readFileType attrValues;
inherit (lib) concatMapAttrs getExe;
inherit (lib.strings) hasSuffix removeSuffix;
inherit (lib.attrsets) foldAttrs;
typst-packages = linkFarm "typst" [
{
name = "typst";
path = "${inputs.typst-packages}";
}
];
in {
# I FKING HATE I HAVE TO DO THIS< BUT IT WORKS< FML!!!!!!!
# TODO :: Find a way to avoid using a direct import.
_module.args.pkgs = import inputs.nixpkgs {
system = "x86_64-linux";
overlays = [inputs.typst.overlays.default];
};
flake.lib = {
buildTypstDoc = src: fonts: name: let
fontsConf = symlinkJoin {
name = "typst-fonts";
paths = fonts;
};
in
pkgs.stdenv.mkDerivation {
name = "${name} Docs";
inherit src;
buildInputs = with pkgs; [typst-dev];
buildPhase = ''
XDG_CACHE_HOME=${typst-packages} ${getExe pkgs.typst-dev} compile --font-path ${fontsConf} main.typ ${name}-docs.pdf
'';
installPhase =
/*
bash
*/
''
mkdir -p $out/Docs
cp ./${name}-docs.pdf $out/Docs/
'';
};
makeWrapper = package:
writeShellApplication {
name = "${package}";
text = ''
XDG_CACHE_HOME=${typst-packages} ${getExe pkgs.${package}} "$@"
'';
};
import' = dir: self: pkgs:
# TODO:: Use fancy oofy goofy functor magic to speed this up
let
readModules = dir:
if pathExists "${dir}.nix" && readFileType "${dir}.nix" == "regular"
then {default = dir;}
else if pathExists dir && readFileType dir == "directory"
then
concatMapAttrs
(
entry: type: let
dirDefault = "${dir}/${entry}/default.nix";
in
if type == "regular" && hasSuffix ".nix" entry
then {${removeSuffix ".nix" entry} = "${dir}/${entry}";}
else if pathExists dirDefault && readFileType dirDefault == "regular"
then {${entry} = dirDefault;}
else {}
)
(readDir dir)
else {};
in
foldAttrs (x: y: x // y) {}
(map (file: import file {inherit self pkgs;}) (attrValues (readModules dir)));
};
}