forked from felixandersen/kivra-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
129 lines (113 loc) · 3.44 KB
/
Copy pathflake.nix
File metadata and controls
129 lines (113 loc) · 3.44 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
{
description = "Kivra Sync - Nix flake to build and develop the project";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
outputs = { self, nixpkgs }: let
systems = [ "x86_64-linux" "aarch64-linux" ];
forAllSystems = f: builtins.listToAttrs (map (system: {
name = system;
value = f system;
}) systems);
in {
packages = forAllSystems (system: let
pkgs = import nixpkgs { inherit system; };
lib = pkgs.lib;
py = pkgs.python3;
pyPkgs = pkgs.python3Packages;
in {
default = pyPkgs.buildPythonApplication {
pname = "kivra-sync";
version = self.rev or "dev";
src = ./.;
format = "other"; # custom installPhase, no setuptools/poetry
dontUseSetuptools = true;
propagatedBuildInputs = with pyPkgs; [
pillow
qrcode
requests
weasyprint
];
# System libraries required by WeasyPrint/Pango/Cairo at runtime
buildInputs = with pkgs; [
cairo
pango
harfbuzz
freetype
fontconfig
gdk-pixbuf
libxml2
libxslt
glib
fribidi
];
nativeBuildInputs = [ pkgs.makeWrapper ];
installPhase = ''
runHook preInstall
site="${py.sitePackages}"
mkdir -p "$out/$site" "$out/bin"
# Install python modules
cp -r kivra interaction storage utils "$out/$site/"
cp __version__.py "$out/$site/"
cp kivra_sync.py "$out/$site/kivra_sync.py"
# Entry point
cat > "$out/bin/kivra-sync" << 'EOF'
#!${py.interpreter}
import sys
from kivra_sync import main
if __name__ == "__main__":
sys.exit(main())
EOF
chmod +x "$out/bin/kivra-sync"
runHook postInstall
'';
# Ensure CFFI can dlopen pango/cairo and friends at runtime
postFixup = let
libPath = lib.makeLibraryPath [
pkgs.pango
pkgs.cairo
pkgs.gdk-pixbuf
pkgs.harfbuzz
pkgs.freetype
pkgs.fontconfig
pkgs.fribidi
pkgs.glib
pkgs.libxml2
pkgs.libxslt
];
in ''
wrapProgram "$out/bin/kivra-sync" \
--prefix LD_LIBRARY_PATH : ${lib.escapeShellArg libPath}
'';
meta = with lib; {
description = "Automation tool to sync documents from Kivra";
homepage = "https://github.com/";
license = licenses.mit;
platforms = platforms.linux;
mainProgram = "kivra-sync";
};
};
});
apps = forAllSystems (system: {
default = {
type = "app";
program = "${self.packages.${system}.default}/bin/kivra-sync";
};
});
devShells = forAllSystems (system: let
pkgs = import nixpkgs { inherit system; };
pyEnv = pkgs.python3.withPackages (ps: with ps; [
pillow qrcode requests weasyprint
]);
in {
default = pkgs.mkShell {
packages = [
pyEnv
# Useful system libs for WeasyPrint during development
pkgs.cairo pkgs.pango pkgs.harfbuzz pkgs.freetype pkgs.fontconfig pkgs.gdk-pixbuf
pkgs.libxml2 pkgs.libxslt pkgs.glib pkgs.fribidi
# Optional: node for release tooling in package.json
pkgs.nodejs
];
};
});
};
}