{ description = "RSSHub - Make RSS Great Again!"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; devenv.url = "github:cachix/devenv"; }; outputs = inputs@{ self, nixpkgs, flake-utils, devenv }: let # Helper to define the RSSHub package makeRSSHub = pkgs: let pnpm = pkgs.pnpm_10; deps = pnpm.fetchDeps { pname = "rsshub"; src = ./.; hash = "sha256-QG1cIkZh+qBA5Dipt0iDLuQpEOI45wdFhuG/CTcRVU8="; fetcherVersion = 2; }; in pkgs.stdenv.mkDerivation rec { pname = "rsshub"; version = "1.0.0"; src = ./.; nativeBuildInputs = with pkgs; [ nodejs_22 pnpm.configHook git ]; buildInputs = with pkgs; [ # Optional: Add chromium for routes that need browser automation # chromium ]; pnpmDeps = deps; # 修补构建脚本以支持离线构建(Nix 构建环境无网络访问) postPatch = '' # 在 registry.ts 中添加 BUILD_ROUTES 模式,使用 directoryImport 但不实际导入模块 substituteInPlace lib/registry.ts \ --replace-fail 'if (config.isPackage)' \ 'if (process.env.BUILD_ROUTES_MODE) { modules = directoryImport({ targetDirectoryPath: path.join(__dirname, "./routes"), importPattern: /\.tsx?$/, }) as typeof modules; } else if (config.isPackage)' ''; # The build phase buildPhase = '' runHook preBuild # 先构建路由元数据(使用 directoryImport 但避免执行模块顶层代码) export BUILD_ROUTES_MODE=1 pnpm run build:routes unset BUILD_ROUTES_MODE # 然后构建应用 export NODE_ENV=production ${pnpm}/bin/pnpm run build runHook postBuild ''; # The install phase installPhase = '' runHook preInstall mkdir -p $out/lib/rsshub cp -r dist $out/lib/rsshub/ cp -r node_modules $out/lib/rsshub/ cp package.json $out/lib/rsshub/ mkdir -p $out/bin cat > $out/bin/rsshub <