Skip to content

Commit dbb6924

Browse files
authored
chore: add Nix flake and NixOS module support (#20597)
* feat(nix): add flake module and offline-friendly build * chore(nix): upgrade to Node.js 24 and pnpm 10 Update devenv.nix to match project dependencies: - Upgrade Node.js from 22 to 24 (aligns with Dockerfile node:24-bookworm) - Upgrade pnpm from 9 to 10 (aligns with package.json pnpm@10.22.0) * test: fix buffer-get test timeout Replace external URL with mock server endpoint to prevent test timeout. The test was trying to fetch from http://example.com which is not mocked, causing it to timeout. Now uses http://rsshub.test/headers which is properly mocked in the test setup.
1 parent e96c640 commit dbb6924

File tree

8 files changed

+721
-22
lines changed

8 files changed

+721
-22
lines changed

β€Ž.envrcβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake .

β€Ž.gitignoreβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.DS_Store
22
.cursorrules
3-
.env*
3+
.env
44
.eslintcache
55
.idea
66
.log

β€Ždevenv.nixβ€Ž

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{ pkgs, lib, config, ... }:
2+
3+
{
4+
# https://devenv.sh/basics/
5+
env = {
6+
NODE_ENV = "dev";
7+
NODE_OPTIONS = "--max-http-header-size=32768";
8+
};
9+
10+
# https://devenv.sh/packages/
11+
packages = with pkgs; [
12+
git
13+
14+
# Optional: Uncomment if you need browser automation
15+
# chromium
16+
];
17+
18+
# https://devenv.sh/languages/
19+
languages.javascript = {
20+
enable = true;
21+
package = pkgs.nodejs_24;
22+
pnpm = {
23+
enable = true;
24+
package = pkgs.pnpm_10;
25+
};
26+
};
27+
28+
# https://devenv.sh/services/
29+
services.redis = {
30+
enable = lib.mkDefault false; # Disabled by default, users can enable in devenv.local.nix
31+
port = 6379;
32+
};
33+
34+
# https://devenv.sh/scripts/
35+
scripts.rsshub-dev.exec = ''
36+
pnpm run dev
37+
'';
38+
39+
scripts.rsshub-build.exec = ''
40+
pnpm run build
41+
'';
42+
43+
scripts.rsshub-start.exec = ''
44+
pnpm start
45+
'';
46+
47+
scripts.rsshub-test.exec = ''
48+
pnpm test
49+
'';
50+
51+
# https://devenv.sh/processes/
52+
processes = {
53+
# Uncomment to auto-start RSSHub in dev mode when entering the shell
54+
# rsshub.exec = "pnpm run dev";
55+
56+
# Example: Auto-start with Redis
57+
# rsshub.exec = "pnpm run dev";
58+
};
59+
60+
# https://devenv.sh/pre-commit-hooks/
61+
pre-commit.hooks = {
62+
# Lint staged files
63+
eslint = {
64+
enable = true;
65+
entry = lib.mkForce "pnpm run format:staged";
66+
};
67+
};
68+
69+
enterShell = ''
70+
echo ""
71+
echo "πŸš€ RSSHub Development Environment"
72+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
73+
echo ""
74+
echo "Node.js: $(node --version)"
75+
echo "pnpm: $(pnpm --version)"
76+
${lib.optionalString config.services.redis.enable ''
77+
echo "Redis: Running on port ${toString config.services.redis.port}"
78+
''}
79+
echo ""
80+
echo "Available commands:"
81+
echo " rsshub-dev - Start development server (pnpm run dev)"
82+
echo " rsshub-build - Build the project (pnpm run build)"
83+
echo " rsshub-start - Start production server (pnpm start)"
84+
echo " rsshub-test - Run tests (pnpm test)"
85+
${lib.optionalString (!config.services.redis.enable) ''
86+
echo ""
87+
echo "πŸ’‘ Tip: Enable Redis by creating devenv.local.nix:"
88+
echo " { services.redis.enable = true; }"
89+
''}
90+
echo ""
91+
echo "Documentation: https://docs.rsshub.app"
92+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
93+
echo ""
94+
95+
# Install dependencies if node_modules doesn't exist
96+
if [ ! -d "node_modules" ]; then
97+
echo "πŸ“¦ Installing dependencies..."
98+
pnpm install
99+
fi
100+
'';
101+
102+
# https://devenv.sh/integrations/dotenv/
103+
dotenv.enable = true; # Automatically load .env file
104+
105+
# Load local overrides if they exist
106+
# Users can create devenv.local.nix for personal customizations
107+
imports = lib.optional (builtins.pathExists ./devenv.local.nix) ./devenv.local.nix;
108+
}

β€Žflake.lockβ€Ž

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

0 commit comments

Comments
Β (0)