1{
2 description = "atproto github";
3
4 inputs = {
5 nixpkgs.url = "github:nixos/nixpkgs";
6 indigo = {
7 url = "github:oppiliappan/indigo";
8 flake = false;
9 };
10 htmx-src = {
11 url = "https://unpkg.com/htmx.org@2.0.4/dist/htmx.min.js";
12 flake = false;
13 };
14 lucide-src = {
15 url = "https://unpkg.com/lucide@latest";
16 flake = false;
17 };
18 ia-fonts-src = {
19 url = "github:iaolo/iA-Fonts";
20 flake = false;
21 };
22 gitignore = {
23 url = "github:hercules-ci/gitignore.nix";
24 inputs.nixpkgs.follows = "nixpkgs";
25 };
26 };
27
28 outputs = {
29 self,
30 nixpkgs,
31 indigo,
32 htmx-src,
33 lucide-src,
34 gitignore,
35 ia-fonts-src,
36 }: let
37 supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
38 forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
39 nixpkgsFor = forAllSystems (system:
40 import nixpkgs {
41 inherit system;
42 overlays = [self.overlays.default];
43 });
44 inherit (gitignore.lib) gitignoreSource;
45 in {
46 overlays.default = final: prev: let
47 goModHash = "sha256-ywhhGrv8KNqy9tCMCnA1PU/RQ/+0Xyitej1L48TcFvI=";
48 buildCmdPackage = name:
49 final.buildGoModule {
50 pname = name;
51 version = "0.1.0";
52 src = gitignoreSource ./.;
53 subPackages = ["cmd/${name}"];
54 vendorHash = goModHash;
55 env.CGO_ENABLED = 0;
56 };
57 in {
58 indigo-lexgen = with final;
59 final.buildGoModule {
60 pname = "indigo-lexgen";
61 version = "0.1.0";
62 src = indigo;
63 subPackages = ["cmd/lexgen"];
64 vendorHash = "sha256-pGc29fgJFq8LP7n/pY1cv6ExZl88PAeFqIbFEhB3xXs=";
65 doCheck = false;
66 };
67
68 appview = with final;
69 final.pkgsStatic.buildGoModule {
70 pname = "appview";
71 version = "0.1.0";
72 src = gitignoreSource ./.;
73 postUnpack = ''
74 pushd source
75 cp -f ${htmx-src} appview/pages/static/htmx.min.js
76 cp -f ${lucide-src} appview/pages/static/lucide.min.js
77 mkdir -p appview/pages/static/fonts
78 cp -f ${ia-fonts-src}/"iA Writer Quattro"/Static/*.ttf appview/pages/static/fonts/
79 cp -f ${ia-fonts-src}/"iA Writer Mono"/Static/*.ttf appview/pages/static/fonts/
80 ${pkgs.tailwindcss}/bin/tailwindcss -i input.css -o appview/pages/static/tw.css
81 popd
82 '';
83 doCheck = false;
84 subPackages = ["cmd/appview"];
85 vendorHash = goModHash;
86 env.CGO_ENABLED = 1;
87 stdenv = pkgsStatic.stdenv;
88 };
89
90 knotserver = with final;
91 final.pkgsStatic.buildGoModule {
92 pname = "knotserver";
93 version = "0.1.0";
94 src = gitignoreSource ./.;
95 subPackages = ["cmd/knotserver"];
96 vendorHash = goModHash;
97 env.CGO_ENABLED = 1;
98 };
99 repoguard = buildCmdPackage "repoguard";
100 keyfetch = buildCmdPackage "keyfetch";
101 };
102 packages = forAllSystems (system: {
103 inherit (nixpkgsFor."${system}") indigo-lexgen appview knotserver repoguard keyfetch;
104 });
105 defaultPackage = forAllSystems (system: nixpkgsFor.${system}.appview);
106 formatter = forAllSystems (system: nixpkgsFor."${system}".alejandra);
107 devShells = forAllSystems (system: let
108 pkgs = nixpkgsFor.${system};
109 staticShell = pkgs.mkShell.override {
110 stdenv = pkgs.pkgsStatic.stdenv;
111 };
112 in {
113 default = staticShell {
114 nativeBuildInputs = [
115 pkgs.go
116 pkgs.air
117 pkgs.gopls
118 pkgs.httpie
119 pkgs.indigo-lexgen
120 pkgs.litecli
121 pkgs.websocat
122 pkgs.tailwindcss
123 ];
124 shellHook = ''
125 cp -f ${htmx-src} appview/pages/static/htmx.min.js
126 cp -f ${lucide-src} appview/pages/static/lucide.min.js
127 cp -f ${ia-fonts-src}/"iA Writer Quattro"/Static/*.ttf appview/pages/static/fonts/
128 cp -f ${ia-fonts-src}/"iA Writer Mono"/Static/*.ttf appview/pages/static/fonts/
129 '';
130 };
131 });
132 apps = forAllSystems (system: let
133 pkgs = nixpkgsFor."${system}";
134 air-watcher = name:
135 pkgs.writeShellScriptBin "run"
136 ''
137 ${pkgs.air}/bin/air -c /dev/null \
138 -build.cmd "${pkgs.tailwindcss}/bin/tailwindcss -i input.css -o ./appview/pages/static/tw.css && ${pkgs.go}/bin/go build -o ./out/${name}.out ./cmd/${name}/main.go" \
139 -build.bin "./out/${name}.out" \
140 -build.include_ext "go,html,css"
141 '';
142 in {
143 watch-appview = {
144 type = "app";
145 program = ''${air-watcher "appview"}/bin/run'';
146 };
147 watch-knotserver = {
148 type = "app";
149 program = ''${air-watcher "knotserver"}/bin/run'';
150 };
151 });
152
153 nixosModules.default = {
154 config,
155 pkgs,
156 lib,
157 ...
158 }:
159 with lib; {
160 options = {
161 services.tangled-appview = {
162 enable = mkOption {
163 type = types.bool;
164 default = false;
165 description = "Enable tangled appview";
166 };
167 port = mkOption {
168 type = types.int;
169 default = 3000;
170 description = "Port to run the appview on";
171 };
172 cookie_secret = mkOption {
173 type = types.str;
174 default = "00000000000000000000000000000000";
175 description = "Cookie secret";
176 };
177 };
178 };
179
180 config = mkIf config.services.tangled-appview.enable {
181 nixpkgs.overlays = [self.overlays.default];
182 systemd.services.tangled-appview = {
183 description = "tangled appview service";
184 wantedBy = ["multi-user.target"];
185
186 serviceConfig = {
187 ListenStream = "0.0.0.0:${toString config.services.tangled-appview.port}";
188 ExecStart = "${pkgs.tangled-appview}/bin/tangled-appview";
189 Restart = "always";
190 };
191
192 environment = {
193 TANGLED_DB_PATH = "appview.db";
194 TANGLED_COOKIE_SECRET = config.services.tangled-appview.cookie_secret;
195 };
196 };
197 };
198 };
199 };
200}