-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
187 lines (159 loc) · 5.35 KB
/
flake.nix
File metadata and controls
187 lines (159 loc) · 5.35 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
{
description = "PaperShelf - A native-feeling desktop app for organizing research papers";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
isLinux = pkgs.stdenv.isLinux;
isDarwin = pkgs.stdenv.isDarwin;
# Linux-specific runtime libraries for Electron
linuxRuntimeLibs = with pkgs; [
glib
gtk3
nss
nspr
atk
at-spi2-atk
libdrm
expat
libxkbcommon
libx11
libxcomposite
libxdamage
libxext
libxfixes
libxrandr
libxcb
mesa
libgbm
libGL
alsa-lib
cups
dbus
pango
cairo
udev
libnotify
];
# Common dependencies for both platforms
commonDeps = with pkgs; [
nodejs_20
python3
gnumake
pkg-config
sqlite
];
# Platform-specific build dependencies
linuxBuildDeps = with pkgs; [
gcc
electron
poppler-utils
] ++ linuxRuntimeLibs;
darwinBuildDeps = with pkgs; [
darwin.cctools
poppler
];
buildDeps = commonDeps
++ (if isLinux then linuxBuildDeps else [])
++ (if isDarwin then darwinBuildDeps else []);
libPath = if isLinux then pkgs.lib.makeLibraryPath linuxRuntimeLibs else "";
# Wrapper script to run the app
papershelf = pkgs.writeShellScriptBin "papershelf" ''
set -e
PROJECT_DIR="''${PAPERSHELF_PROJECT_DIR:-$(pwd)}"
if [ ! -f "$PROJECT_DIR/package.json" ]; then
echo "Error: package.json not found in $PROJECT_DIR"
echo "Run this command from the PaperShelf project directory,"
echo "or set PAPERSHELF_PROJECT_DIR to the project path."
exit 1
fi
cd "$PROJECT_DIR"
# Set up environment
export PATH="${pkgs.nodejs_20}/bin:$PROJECT_DIR/node_modules/.bin:$PATH"
export npm_config_build_from_source=true
export SQLITE3_INCLUDE_DIR="${pkgs.sqlite.dev}/include"
export SQLITE3_LIB_DIR="${pkgs.sqlite.out}/lib"
${if isLinux then ''
export LD_LIBRARY_PATH="${libPath}:$LD_LIBRARY_PATH"
export ELECTRON_OZONE_PLATFORM_HINT=auto
'' else ""}
# Install dependencies if needed
if [ ! -d "node_modules" ]; then
echo "Installing dependencies..."
${pkgs.nodejs_20}/bin/npm install
fi
# Run the app
echo "Starting PaperShelf..."
exec ${pkgs.nodejs_20}/bin/npm run dev
'';
# Build script (builds but doesn't run)
papershelf-build = pkgs.writeShellScriptBin "papershelf-build" ''
set -e
PROJECT_DIR="''${PAPERSHELF_PROJECT_DIR:-$(pwd)}"
if [ ! -f "$PROJECT_DIR/package.json" ]; then
echo "Error: package.json not found in $PROJECT_DIR"
exit 1
fi
cd "$PROJECT_DIR"
export PATH="${pkgs.nodejs_20}/bin:$PROJECT_DIR/node_modules/.bin:$PATH"
export npm_config_build_from_source=true
export SQLITE3_INCLUDE_DIR="${pkgs.sqlite.dev}/include"
export SQLITE3_LIB_DIR="${pkgs.sqlite.out}/lib"
${if isLinux then ''
export LD_LIBRARY_PATH="${libPath}:$LD_LIBRARY_PATH"
'' else ""}
if [ ! -d "node_modules" ]; then
echo "Installing dependencies..."
${pkgs.nodejs_20}/bin/npm install
fi
echo "Building PaperShelf..."
${pkgs.nodejs_20}/bin/npm run build
echo "Build complete! Output in dist/"
'';
in
{
packages = {
default = papershelf;
build = papershelf-build;
};
apps = {
default = {
type = "app";
program = "${papershelf}/bin/papershelf";
};
build = {
type = "app";
program = "${papershelf-build}/bin/papershelf-build";
};
};
devShells.default = pkgs.mkShell {
buildInputs = buildDeps;
shellHook = ''
# Set up npm to use local node_modules/.bin
export PATH="$PWD/node_modules/.bin:$PATH"
# Fix for native module compilation
export npm_config_build_from_source=true
${if isLinux then ''
# Required for Electron on Linux
export ELECTRON_OZONE_PLATFORM_HINT=auto
# Help native modules find system libraries
export LD_LIBRARY_PATH="${libPath}:$LD_LIBRARY_PATH"
'' else ""}
echo "PaperShelf development environment loaded"
echo "Run 'npm install' to install dependencies"
echo "Run 'npm run dev' to start development server"
'';
# Environment variables for better-sqlite3
SQLITE3_INCLUDE_DIR = "${pkgs.sqlite.dev}/include";
SQLITE3_LIB_DIR = "${pkgs.sqlite.out}/lib";
};
}
);
}