1{
2 lib,
3 stdenv,
4 nodejs,
5 pnpm,
6 fetchFromGitHub,
7 buildGoModule,
8 installShellFiles,
9 callPackage,
10 nixosTests,
11 authelia-web ? callPackage ./web.nix { inherit nodejs pnpm fetchFromGitHub; },
12}:
13
14let
15 inherit (import ./sources.nix { inherit fetchFromGitHub; })
16 pname
17 version
18 src
19 vendorHash
20 ;
21
22 web = authelia-web;
23in
24buildGoModule rec {
25 inherit
26 pname
27 version
28 src
29 vendorHash
30 ;
31
32 nativeBuildInputs = [ installShellFiles ];
33
34 ## FIXME: add swagger-ui https://github.com/authelia/authelia/blob/master/cmd/authelia-scripts/cmd/build.go#L148
35 postPatch = ''
36 cp -r api internal/server/public_html
37 cp -r ${web}/share/authelia-web/* internal/server/public_html
38 '';
39
40 subPackages = [ "cmd/authelia" ];
41
42 ldflags =
43 let
44 p = "github.com/authelia/authelia/v${lib.versions.major version}/internal/utils";
45 in
46 [
47 "-s"
48 "-w"
49 "-X ${p}.BuildTag=v${version}"
50 "-X '${p}.BuildState=tagged clean'"
51 "-X ${p}.BuildBranch=v${version}"
52 "-X ${p}.BuildExtra=nixpkgs"
53 ];
54
55 # It is required to set this to avoid a change in the
56 # handling of sync map in go 1.24+
57 # Upstream issue: https://github.com/authelia/authelia/issues/8980
58 env.GOEXPERIMENT = "nosynchashtriemap";
59
60 # several tests with networking and several that want chromium
61 doCheck = false;
62
63 postInstall = ''
64 mkdir -p $out/etc/authelia
65 cp config.template.yml $out/etc/authelia
66 ''
67 + lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
68 installShellCompletion --cmd authelia \
69 --bash <($out/bin/authelia completion bash) \
70 --fish <($out/bin/authelia completion fish) \
71 --zsh <($out/bin/authelia completion zsh)
72 '';
73
74 doInstallCheck = true;
75 installCheckPhase = ''
76 runHook preInstallCheck
77
78 $out/bin/authelia --help
79 $out/bin/authelia --version | grep "v${version}"
80 $out/bin/authelia build-info | grep 'v${version}\|nixpkgs'
81
82 runHook postInstallCheck
83 '';
84
85 passthru = {
86 # if overriding replace the postPatch to put your web UI output in internal/server/public_html
87 inherit web;
88 updateScript = ./update.sh;
89 tests = { inherit (nixosTests) authelia; };
90 };
91
92 meta = with lib; {
93 homepage = "https://www.authelia.com/";
94 changelog = "https://github.com/authelia/authelia/releases/tag/v${version}";
95 description = "Single Sign-On Multi-Factor portal for web apps";
96 longDescription = ''
97 Authelia is an open-source authentication and authorization server
98 providing two-factor authentication and single sign-on (SSO) for your
99 applications via a web portal. It acts as a companion for reverse proxies
100 like nginx, Traefik, caddy or HAProxy to let them know whether requests
101 should either be allowed or redirected to Authelia's portal for
102 authentication.
103 '';
104 license = licenses.asl20;
105 maintainers = with maintainers; [
106 jk
107 dit7ya
108 nicomem
109 ];
110 mainProgram = "authelia";
111 };
112}