forked from obsidian-html/obsidian-html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
103 lines (90 loc) · 3.09 KB
/
flake.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{
description = "obsidian-html builder";
inputs.flake-utils = {
url = "github:numtide/flake-utils";
};
inputs.nixpkgs = {
url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs = {
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
};
makeYaml = config: let
configFile = pkgs.writeText "config.yml" (builtins.toJSON config);
in
pkgs.runCommandNoCC "config.yml" {} ''
(${pkgs.yj}/bin/yj -jy < ${configFile}) > $out
'';
setup = builtins.fromJSON (builtins.readFile (pkgs.runCommandNoCC "setup.cfg" {} ''
cat ${./setup.cfg} | ${pkgs.python3Packages.jc}/bin/jc --ini > $out
''));
depNames = map (x: builtins.head(pkgs.lib.strings.splitString " " x)) (pkgs.lib.remove "" (pkgs.lib.splitString "\n"
setup
.options
.install_requires));
deps = pkgs.lib.attrsets.attrVals depNames pkgs.python3Packages;
in rec {
packages.default = pkgs.python3.pkgs.buildPythonApplication rec {
pname = setup.metadata.name;
version = setup.metadata.version;
format = "pyproject";
checkPhase = ''
export PATH="$PATH:$out/bin"
${pkgs.python3}/bin/python3 ci/tests/basic_regression_test.py
'';
src = ./.;
propagatedBuildInputs = deps;
};
checks.default = packages.default;
devShells.default = let
myPython = pkgs.python3.withPackages (p: pkgs.lib.attrsets.attrVals depNames p);
in
pkgs.mkShell {
buildInputs = [
myPython
];
shellHook = ''
PYTHONPATH=${myPython}/${myPython.sitePackages}
'';
};
mkProject = args: let
config =
{
obsidian_folder_path_str = args.src;
obsidian_entrypoint_path_str = "${args.src}/${args.entrypoint}";
md_folder_path_str = "mdout";
md_entrypoint_path_str = "mdout/${args.entrypoint}";
html_output_folder_path_str = "htmlout";
copy_vault_to_tempdir = false;
site_name = args.name;
}
// (removeAttrs args ["obsidian_folder_path_str" "entrypoint" "src" "name" "md_folder_path_str" "md_entrypoint_path_str" "html_output_folder_path_str"]);
yamlConfig = makeYaml config;
in {
compile = pkgs.runCommandNoCC args.name {outputs = ["out" "md"];} ''
ln -s $out htmlout
ln -s $md mdout
${packages.default}/bin/obsidianhtml convert -i ${yamlConfig}
'';
run = pkgs.writeShellApplication {
name = "run";
text = ''
TEMP=$(mktemp -d)
cd "$TEMP"
${packages.default}/bin/obsidianhtml run -i ${yamlConfig}
'';
};
};
apps.default = flake-utils.lib.mkApp {
drv = packages.default;
};
}
);
}