acr-cli: init at 0.14 (#359508)
[NixPkgs.git] / pkgs / by-name / zi / zitadel / package.nix
blobd744ed153c8382e5ae6d8294daeb65d733115d97
1 { stdenv
2 , buildGoModule
3 , callPackage
4 , fetchFromGitHub
5 , lib
7 , buf
8 , cacert
9 , grpc-gateway
10 , protoc-gen-go
11 , protoc-gen-go-grpc
12 , protoc-gen-validate
13 , sass
14 , statik
17 let
18   version = "2.58.3";
19   zitadelRepo = fetchFromGitHub {
20     owner = "zitadel";
21     repo = "zitadel";
22     rev = "v${version}";
23     hash = "sha256-RXcJwGO8OQ38lbuy2uLTSkh6yUbyqY42FpwgMXC3g6c=";
24   };
25   goModulesHash = "sha256-gp17dP67HX7Tx3Gq+kEu9xCYkfs/rGpqLFiKT7cKlrc=";
27   buildZitadelProtocGen = name:
28     buildGoModule {
29       pname = "protoc-gen-${name}";
30       inherit version;
32       src = zitadelRepo;
34       proxyVendor = true;
35       vendorHash = goModulesHash;
37       buildPhase = ''
38         go install internal/protoc/protoc-gen-${name}/main.go
39       '';
41       postInstall = ''
42         mv $out/bin/main $out/bin/protoc-gen-${name}
43       '';
44     };
46   protoc-gen-authoption = buildZitadelProtocGen "authoption";
47   protoc-gen-zitadel = buildZitadelProtocGen "zitadel";
49   # Buf downloads dependencies from an external repo - there doesn't seem to
50   # really be any good way around it. We'll use a fixed-output derivation so it
51   # can download what it needs, and output the relevant generated code for use
52   # during the main build.
53   generateProtobufCode =
54     { pname
55     , nativeBuildInputs ? [ ]
56     , bufArgs ? ""
57     , workDir ? "."
58     , outputPath
59     , hash
60     }:
61     stdenv.mkDerivation {
62       name = "${pname}-buf-generated";
64       src = zitadelRepo;
65       patches = [ ./console-use-local-protobuf-plugins.patch ];
67       nativeBuildInputs = nativeBuildInputs ++ [ buf cacert ];
69       buildPhase = ''
70         cd ${workDir}
71         HOME=$TMPDIR buf generate ${bufArgs}
72       '';
74       installPhase = ''
75         cp -r ${outputPath} $out
76       '';
78       outputHashMode = "recursive";
79       outputHashAlgo = "sha256";
80       outputHash = hash;
81     };
83   protobufGenerated = generateProtobufCode {
84     pname = "zitadel";
85     nativeBuildInputs = [
86       grpc-gateway
87       protoc-gen-authoption
88       protoc-gen-go
89       protoc-gen-go-grpc
90       protoc-gen-validate
91       protoc-gen-zitadel
92     ];
93     outputPath = ".artifacts";
94     hash = "sha256-KRf11PNn7LtVFjG3NYUtPEJtLNbnxfzR4B69US07B3k=";
95   };
97 buildGoModule rec {
98   name = "zitadel";
99   inherit version;
101   src = zitadelRepo;
103   nativeBuildInputs = [ sass statik ];
105   proxyVendor = true;
106   vendorHash = goModulesHash;
107   ldflags = [ "-X 'github.com/zitadel/zitadel/cmd/build.version=${version}'" ];
109   # Adapted from Makefile in repo, with dependency fetching and protobuf codegen
110   # bits removed
111   preBuild = ''
112     mkdir -p pkg/grpc
113     cp -r ${protobufGenerated}/grpc/github.com/zitadel/zitadel/pkg/grpc/* pkg/grpc
114     mkdir -p openapi/v2/zitadel
115     cp -r ${protobufGenerated}/grpc/zitadel/ openapi/v2/zitadel
117     go generate internal/api/ui/login/static/resources/generate.go
118     go generate internal/api/ui/login/statik/generate.go
119     go generate internal/notification/statik/generate.go
120     go generate internal/statik/generate.go
122     mkdir -p docs/apis/assets
123     go run internal/api/assets/generator/asset_generator.go -directory=internal/api/assets/generator/ -assets=docs/apis/assets/assets.md
125     cp -r ${passthru.console}/* internal/api/ui/console/static
126   '';
128   doCheck = false;
130   installPhase = ''
131     mkdir -p $out/bin
132     install -Dm755 $GOPATH/bin/zitadel $out/bin/
133   '';
135   passthru = {
136     console = callPackage
137       (import ./console.nix {
138         inherit generateProtobufCode version zitadelRepo;
139       })
140       { };
141   };
143   meta = with lib; {
144     description = "Identity and access management platform";
145     homepage = "https://zitadel.com/";
146     downloadPage = "https://github.com/zitadel/zitadel/releases";
147     platforms = platforms.linux ++ platforms.darwin;
148     license = licenses.asl20;
149     sourceProvenance = [ sourceTypes.fromSource ];
150     maintainers = [ maintainers.nrabulinski ];
151   };