C2(authentik-source-build): impl API client generation derivations
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c563081377
commit
d6f76a3058
5 changed files with 141 additions and 1 deletions
28
containers/authentik/api-go-vendor-hook.nix
Normal file
28
containers/authentik/api-go-vendor-hook.nix
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# Setup hook that injects generated Go API client into the vendor directory
|
||||
# Replaces vendor/goauthentik.io/api/v3/ with freshly generated client-go output
|
||||
# Skips during FOD (fixed-output derivation) builds to keep vendorHash stable
|
||||
{ pkgs ? import <nixpkgs> { }, sources ? import ./sources.nix { inherit pkgs; } }:
|
||||
|
||||
let
|
||||
client-go = import ./client-go.nix { inherit pkgs sources; };
|
||||
in
|
||||
pkgs.makeSetupHook
|
||||
{
|
||||
name = "authentik-api-go-vendor-hook";
|
||||
}
|
||||
(
|
||||
pkgs.writeShellScript "authentik-api-go-vendor-hook" ''
|
||||
authentikApiGoVendorHook() {
|
||||
chmod -R +w vendor/goauthentik.io/api
|
||||
rm -rf vendor/goauthentik.io/api/v3
|
||||
cp -r ${client-go} vendor/goauthentik.io/api/v3
|
||||
|
||||
echo "Finished authentikApiGoVendorHook"
|
||||
}
|
||||
|
||||
# don't run for FOD, e.g. the goModules build
|
||||
if [ -z ''${outputHash-} ]; then
|
||||
postConfigureHooks+=(authentikApiGoVendorHook)
|
||||
fi
|
||||
''
|
||||
)
|
||||
47
containers/authentik/client-go.nix
Normal file
47
containers/authentik/client-go.nix
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# Generate Go API client bindings from authentik's OpenAPI schema
|
||||
# Uses openapi-generator-cli to produce Go code from schema.yml
|
||||
{ pkgs ? import <nixpkgs> { }, sources ? import ./sources.nix { inherit pkgs; } }:
|
||||
|
||||
pkgs.stdenvNoCC.mkDerivation {
|
||||
pname = "authentik-client-go";
|
||||
version = "3.${sources.version}";
|
||||
inherit (sources) meta;
|
||||
|
||||
src = sources.client-go-src;
|
||||
|
||||
# Docker volume path /local → local pwd
|
||||
postPatch = ''
|
||||
substituteInPlace ./config.yaml \
|
||||
--replace-fail '/local' "$(pwd)"
|
||||
'';
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
openapi-generator-cli
|
||||
go
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
|
||||
openapi-generator-cli generate \
|
||||
-i ${sources.src}/schema.yml -o $out \
|
||||
-g go \
|
||||
-c ./config.yaml
|
||||
|
||||
gofmt -w $out
|
||||
|
||||
runHook postBuild
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
cp go.mod go.sum $out
|
||||
|
||||
cd $out
|
||||
rm -rf test
|
||||
rm -f .travis.yml git_push.sh
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
}
|
||||
36
containers/authentik/client-ts.nix
Normal file
36
containers/authentik/client-ts.nix
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# Generate TypeScript fetch client bindings from authentik's OpenAPI schema
|
||||
# Uses openapi-generator-cli to produce TypeScript code, then compiles with tsc
|
||||
{ pkgs ? import <nixpkgs> { }, sources ? import ./sources.nix { inherit pkgs; } }:
|
||||
|
||||
pkgs.stdenvNoCC.mkDerivation {
|
||||
pname = "authentik-client-ts";
|
||||
inherit (sources) version src meta;
|
||||
|
||||
# Docker volume path /local → local pwd
|
||||
postPatch = ''
|
||||
substituteInPlace ./scripts/api/ts-config.yaml \
|
||||
--replace-fail '/local' "$(pwd)"
|
||||
'';
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
nodejs
|
||||
openapi-generator-cli
|
||||
typescript
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
|
||||
openapi-generator-cli generate \
|
||||
-i ./schema.yml -o $out \
|
||||
-g typescript-fetch \
|
||||
-c ./scripts/api/ts-config.yaml \
|
||||
--additional-properties=npmVersion=${sources.version} \
|
||||
--git-repo-id authentik --git-user-id goauthentik
|
||||
|
||||
cd $out
|
||||
npm run build
|
||||
|
||||
runHook postBuild
|
||||
'';
|
||||
}
|
||||
30
containers/authentik/sources.nix
Normal file
30
containers/authentik/sources.nix
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# Centralized version and source pinning for authentik 2026.2.0
|
||||
# All sources fetched from forge mirrors for supply chain control
|
||||
{ pkgs ? import <nixpkgs> { } }:
|
||||
|
||||
let
|
||||
version = "2026.2.0";
|
||||
in
|
||||
{
|
||||
inherit version;
|
||||
|
||||
# Main authentik repo — provides schema.yml, Python backend, web UI, Go server
|
||||
src = pkgs.fetchgit {
|
||||
url = "https://forge.ops.eblu.me/mirrors/authentik.git";
|
||||
rev = "version/${version}";
|
||||
hash = "sha256-pVQ34cZYX3hlk6hF1aZ/n32xMqTF4Jmp0G0VGDU7iXc=";
|
||||
};
|
||||
|
||||
# Go API client repo — provides config.yaml, go.mod, go.sum, templates
|
||||
client-go-src = pkgs.fetchgit {
|
||||
url = "https://forge.ops.eblu.me/mirrors/authentik-client-go.git";
|
||||
rev = "v3.${version}";
|
||||
hash = "sha256-DwXw/0QcSDYQKVhPA8tStrSoZooriQex/9FxSJtR/QY=";
|
||||
};
|
||||
|
||||
meta = with pkgs.lib; {
|
||||
description = "Authentik identity provider";
|
||||
homepage = "https://goauthentik.io";
|
||||
license = licenses.mit;
|
||||
};
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
---
|
||||
title: Mirror Authentik Build Dependencies
|
||||
modified: 2026-02-28
|
||||
status: active
|
||||
tags:
|
||||
- how-to
|
||||
- authentik
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue