199 lines
6.1 kB
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
${pkgs.tailwindcss}/bin/tailwindcss -i input.css -o appview/pages/static/tw.css
78
popd
79
'';
80
doCheck = false;
81
subPackages = ["cmd/appview"];
82
vendorHash = goModHash;
83
env.CGO_ENABLED = 1;
84
stdenv = pkgsStatic.stdenv;
85
};
86
87
knotserver = with final;
88
final.pkgsStatic.buildGoModule {
89
pname = "knotserver";
90
version = "0.1.0";
91
src = gitignoreSource ./.;
92
subPackages = ["cmd/knotserver"];
93
vendorHash = goModHash;
94
env.CGO_ENABLED = 1;
95
};
96
repoguard = buildCmdPackage "repoguard";
97
keyfetch = buildCmdPackage "keyfetch";
98
};
99
packages = forAllSystems (system: {
100
inherit (nixpkgsFor."${system}") indigo-lexgen appview knotserver repoguard keyfetch;
101
});
102
defaultPackage = forAllSystems (system: nixpkgsFor.${system}.appview);
103
formatter = forAllSystems (system: nixpkgsFor."${system}".alejandra);
104
devShells = forAllSystems (system: let
105
pkgs = nixpkgsFor.${system};
106
staticShell = pkgs.mkShell.override {
107
stdenv = pkgs.pkgsStatic.stdenv;
108
};
109
in {
110
default = staticShell {
111
nativeBuildInputs = [
112
pkgs.go
113
pkgs.air
114
pkgs.gopls
115
pkgs.httpie
116
pkgs.indigo-lexgen
117
pkgs.litecli
118
pkgs.websocat
119
pkgs.tailwindcss
120
];
121
shellHook = ''
122
cp -f ${htmx-src} appview/pages/static/htmx.min.js
123
cp -f ${lucide-src} appview/pages/static/lucide.min.js
124
cp -f ${ia-fonts-src}/"iA Writer Quattro"/Static/*.ttf appview/pages/static/fonts/
125
cp -f ${ia-fonts-src}/"iA Writer Mono"/Static/*.ttf appview/pages/static/fonts/
126
'';
127
};
128
});
129
apps = forAllSystems (system: let
130
pkgs = nixpkgsFor."${system}";
131
air-watcher = name:
132
pkgs.writeShellScriptBin "run"
133
''
134
${pkgs.air}/bin/air -c /dev/null \
135
-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" \
136
-build.bin "./out/${name}.out" \
137
-build.include_ext "go,html,css"
138
'';
139
in {
140
watch-appview = {
141
type = "app";
142
program = ''${air-watcher "appview"}/bin/run'';
143
};
144
watch-knotserver = {
145
type = "app";
146
program = ''${air-watcher "knotserver"}/bin/run'';
147
};
148
});
149
150
nixosModules.default = {
151
config,
152
pkgs,
153
lib,
154
...
155
}:
156
with lib; {
157
options = {
158
services.tangled-appview = {
159
enable = mkOption {
160
type = types.bool;
161
default = false;
162
description = "Enable tangled appview";
163
};
164
port = mkOption {
165
type = types.int;
166
default = 3000;
167
description = "Port to run the appview on";
168
};
169
cookie_secret = mkOption {
170
type = types.str;
171
default = "00000000000000000000000000000000";
172
description = "Cookie secret";
173
};
174
};
175
};
176
177
config = mkIf config.services.tangled-appview.enable {
178
nixpkgs.overlays = [self.overlays.default];
179
systemd.services.tangled-appview = {
180
description = "tangled appview service";
181
wantedBy = ["multi-user.target"];
182
183
serviceConfig = {
184
ListenStream = "0.0.0.0:${toString config.services.tangled-appview.port}";
185
ExecStart = "${pkgs.tangled-appview}/bin/tangled-appview";
186
Restart = "always";
187
};
188
189
environment = {
190
TANGLED_PORT = "${toString config.services.tangled-appview.port}";
191
TANGLED_HOST = "localhost";
192
TANGLED_DB_PATH = "appview.db";
193
TANGLED_COOKIE_SECRET = config.services.tangled-appview.cookie_secret;
194
};
195
};
196
};
197
};
198
};
199
}
200