everything you need to create an atproto appview
1{
2 description = "atproto starterkit";
3
4 inputs = {
5 nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
6 gomod2nix = {
7 url = "github:nix-community/gomod2nix";
8 inputs.nixpkgs.follows = "nixpkgs";
9 };
10 };
11
12 outputs = {
13 self,
14 nixpkgs,
15 gomod2nix,
16 ...
17 }: let
18 supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
19 forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
20 nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system});
21 in {
22 devShells = forAllSystems (system: let
23 pkgs = nixpkgsFor.${system};
24 staticShell = pkgs.mkShell.override {
25 stdenv = pkgs.pkgsStatic.stdenv;
26 };
27 in {
28 default = staticShell {
29 nativeBuildInputs = [
30 pkgs.go
31 pkgs.air
32 pkgs.gopls
33 pkgs.httpie
34 pkgs.litecli
35 pkgs.websocat
36 pkgs.tailwindcss
37 pkgs.nixos-shell
38 pkgs.redis
39 pkgs.coreutils # for those of us who are on systems that use busybox (alpine)
40 gomod2nix.legacyPackages.${system}.gomod2nix
41 ];
42 shellHook = ''
43 export TANGLED_OAUTH_CLIENT_KID="$(date +%s)"
44 '';
45 env.CGO_ENABLED = 1;
46 };
47 });
48
49 apps = forAllSystems (system: let
50 pkgs = nixpkgsFor."${system}";
51 in {
52 lexgen = {
53 type = "app";
54 program =
55 (pkgs.writeShellApplication {
56 name = "lexgen";
57 text = ''
58 if ! command -v lexgen > /dev/null; then
59 echo "error: must be executed from devshell"
60 exit 1
61 fi
62
63 rootDir=$(jj --ignore-working-copy root || git rev-parse --show-toplevel) || (echo "error: can't find repo root?"; exit 1)
64 cd "$rootDir"
65
66 outdir=api/lexicons
67
68 rm -f $outdir/*
69 lexgen --build-file lexicon-build-config.json lexicons
70 sed -i.bak 's/\tutil/\/\/\tutil/' $outdir/*
71 # lexgen generates incomplete Marshaler/Unmarshaler for union types
72 find $outdir/*.go -not -name "cbor_gen.go" -exec \
73 sed -i '/^func.*\(MarshalCBOR\|UnmarshalCBOR\)/,/^}/ s/^/\/\/ /' {} +
74 ${pkgs.gotools}/bin/goimports -w $outdir/*
75 go run ./cmd/cborgen/
76 lexgen --build-file lexicon-build-config.json lexicons
77 rm $outdir/*.bak
78 '';
79 })
80 + /bin/lexgen;
81 };
82 gomod2nix = {
83 type = "app";
84 program = toString (pkgs.writeShellScript "gomod2nix" ''
85 ${gomod2nix.legacyPackages.${system}.gomod2nix}/bin/gomod2nix generate --outdir ./nix
86 '');
87 };
88 });
89 };
90}