124 lines
3.9 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
gitignore = {
15
url = "github:hercules-ci/gitignore.nix";
16
inputs.nixpkgs.follows = "nixpkgs";
17
};
18
};
19
20
outputs = {
21
self,
22
nixpkgs,
23
indigo,
24
htmx-src,
25
gitignore,
26
}: let
27
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
28
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
29
nixpkgsFor = forAllSystems (system:
30
import nixpkgs {
31
inherit system;
32
overlays = [self.overlays.default];
33
});
34
inherit (gitignore.lib) gitignoreSource;
35
in {
36
overlays.default = final: prev: {
37
indigo-lexgen = with final;
38
final.buildGoModule {
39
pname = "indigo-lexgen";
40
version = "0.1.0";
41
src = indigo;
42
subPackages = ["cmd/lexgen"];
43
vendorHash = "sha256-pGc29fgJFq8LP7n/pY1cv6ExZl88PAeFqIbFEhB3xXs=";
44
doCheck = false;
45
};
46
47
appview = with final;
48
final.pkgsStatic.buildGoModule {
49
pname = "appview";
50
version = "0.1.0";
51
src = gitignoreSource ./.;
52
postConfigureHook = ''
53
cp -f ${htmx-src} appview/pages/static/htmx.min.js
54
${pkgs.tailwindcss}/bin/tailwindcss -i input.css -o appview/pages/static/tw.css
55
'';
56
subPackages = ["cmd/appview"];
57
vendorHash = "sha256-QgUPTOgAdKUTg+ztfs194G7pt3/qDtqTMkDRmMECxSo=";
58
env.CGO_ENABLED = 1;
59
stdenv = pkgsStatic.stdenv;
60
};
61
62
knotserver = with final;
63
final.pkgsStatic.buildGoModule {
64
pname = "knotserver";
65
version = "0.1.0";
66
src = gitignoreSource ./.;
67
subPackages = ["cmd/knotserver"];
68
vendorHash = "sha256-QgUPTOgAdKUTg+ztfs194G7pt3/qDtqTMkDRmMECxSo=";
69
env.CGO_ENABLED = 1;
70
nativeBuildInputs = with pkgsMusl; [ pkg-config ];
71
72
# Add these ldflags for static compilation
73
ldflags = [ "-s" "-w" "-linkmode external" ''-extldflags "-static -L${pkgsStatic.musl}/lib"'' ];
74
75
# Use static stdenv
76
stdenv = pkgMusl.stdenv;
77
};
78
};
79
packages = forAllSystems (system: {
80
inherit (nixpkgsFor."${system}") indigo-lexgen appview knotserver;
81
});
82
defaultPackage = forAllSystems (system: nixpkgsFor.${system}.appview);
83
formatter = forAllSystems (system: nixpkgsFor."${system}".alejandra);
84
devShells = forAllSystems (system: let
85
pkgs = nixpkgsFor.${system};
86
staticShell = pkgs.mkShell.override {
87
stdenv = pkgs.pkgsStatic.stdenv;
88
};
89
in {
90
default = staticShell {
91
nativeBuildInputs = [
92
pkgs.go
93
pkgs.air
94
pkgs.gopls
95
pkgs.httpie
96
pkgs.indigo-lexgen
97
pkgs.litecli
98
pkgs.websocat
99
pkgs.tailwindcss
100
];
101
};
102
});
103
apps = forAllSystems (system: let
104
pkgs = nixpkgsFor."${system}";
105
air-watcher = name:
106
pkgs.writeShellScriptBin "run"
107
''
108
${pkgs.air}/bin/air -c /dev/null \
109
-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" \
110
-build.bin "./out/${name}.out" \
111
-build.include_ext "go,html,css"
112
'';
113
in {
114
watch-appview = {
115
type = "app";
116
program = ''${air-watcher "appview"}/bin/run'';
117
};
118
watch-knotserver = {
119
type = "app";
120
program = ''${air-watcher "knotserver"}/bin/run'';
121
};
122
});
123
};
124
}
125