selfhostable, read-only reddit client
at main 4.0 kB view raw
1{ 2 inputs = { 3 nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 4 }; 5 6 outputs = { 7 self, 8 nixpkgs, 9 }: let 10 supportedSystems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin"]; 11 forAllSystems = nixpkgs.lib.genAttrs supportedSystems; 12 nixpkgsFor = forAllSystems (system: 13 import nixpkgs { 14 inherit system; 15 overlays = [ 16 self.overlays.default 17 ]; 18 }); 19 in { 20 overlays.default = final: prev: let 21 pname = "lurker"; 22 version = "0.1.0"; 23 in { 24 node_modules = with final; 25 stdenv.mkDerivation { 26 pname = "lurker-node-modules"; 27 version = "0.0.1"; 28 impureEnvVars = 29 lib.fetchers.proxyImpureEnvVars 30 ++ ["GIT_PROXY_COMMAND" "SOCKS_SERVER"]; 31 src = ./.; 32 nativeBuildInputs = [bun]; 33 buildInputs = [nodejs-slim_latest]; 34 dontConfigure = true; 35 dontFixup = true; 36 buildPhase = '' 37 bun install --no-progress --frozen-lockfile 38 ''; 39 installPhase = '' 40 mkdir -p $out/node_modules 41 cp -R ./node_modules/* $out/node_modules 42 ls -la $out/node_modules 43 ''; 44 outputHash = "sha256-wCMsk/gR+U5fCHcRj7Mxvh9Lg6wZAtMn7CvjyCPar+g="; 45 outputHashAlgo = "sha256"; 46 outputHashMode = "recursive"; 47 }; 48 lurker = with final; 49 stdenv.mkDerivation { 50 inherit pname version; 51 src = ./.; 52 nativeBuildInputs = [makeBinaryWrapper]; 53 buildInputs = [bun]; 54 55 buildPhase = '' 56 runHook preBuild 57 runHook postBuild 58 ''; 59 60 dontFixup = true; 61 62 installPhase = '' 63 runHook preInstall 64 65 mkdir -p $out/bin 66 67 ln -s ${node_modules}/node_modules $out 68 cp -R ./* $out 69 70 makeBinaryWrapper ${bun}/bin/bun $out/bin/$pname \ 71 --prefix PATH : ${lib.makeBinPath [bun]} \ 72 --add-flags "run --prefer-offline --no-install $out/src/index.js" 73 74 ''; 75 }; 76 }; 77 78 devShell = forAllSystems (system: let 79 pkgs = nixpkgsFor."${system}"; 80 in 81 pkgs.mkShell { 82 nativeBuildInputs = [ 83 pkgs.bun 84 pkgs.biome 85 pkgs.typescript-language-server 86 ]; 87 }); 88 89 packages = forAllSystems (system: { 90 inherit (nixpkgsFor."${system}") lurker node_modules; 91 }); 92 93 defaultPackage = forAllSystems (system: nixpkgsFor."${system}".lurker); 94 95 apps = forAllSystems (system: let 96 pkgs = nixpkgsFor.${system}; 97 in { 98 default = { 99 type = "app"; 100 program = "${pkgs.lurker}/bin/lurker"; 101 }; 102 }); 103 104 formatter = forAllSystems (system: nixpkgsFor."${system}".alejandra); 105 106 nixosModules.default = { 107 config, 108 pkgs, 109 lib, 110 ... 111 }: 112 with lib; { 113 options = { 114 services.lurker = { 115 enable = mkOption { 116 type = types.bool; 117 default = false; 118 description = "Enable lurker"; 119 }; 120 port = mkOption { 121 type = types.int; 122 default = 3000; 123 description = "Port to run lurker on"; 124 }; 125 }; 126 }; 127 128 config = mkIf config.services.lurker.enable { 129 nixpkgs.overlays = [self.overlays.default]; 130 systemd.services.lurker = { 131 description = "lurker service"; 132 wantedBy = ["multi-user.target"]; 133 134 serviceConfig = { 135 ListenStream = "0.0.0.0:${toString config.services.lurker.port}"; 136 ExecStart = "${pkgs.lurker}/bin/lurker"; 137 Restart = "always"; 138 }; 139 140 # If the binary needs specific environment variables, set them here 141 environment = { 142 LURKER_PORT = "${toString config.services.lurker.port}"; 143 }; 144 }; 145 }; 146 }; 147 }; 148}