a (hacky, wip) multi-tenant oidc-terminating reverse proxy, written in anger on top of pingora
1{
2 description = "An oauth2/oidc1 proxy, written in anger";
3
4 # Flake inputs
5 inputs = {
6 nixpkgs.url = "github:NixOS/nixpkgs"; # also valid: "nixpkgs"
7 rust-overlay.url = "github:oxalica/rust-overlay"; # A helper for Rust + Nix
8
9 # crane, for nicer caching when building rust
10 crane.url = "github:ipetkov/crane";
11 };
12
13 # Flake outputs
14 outputs = { self, nixpkgs, rust-overlay, crane }:
15 let
16 # Overlays enable you to customize the Nixpkgs attribute set
17 overlays = [
18 # Makes a `rust-bin` attribute available in Nixpkgs
19 (import rust-overlay)
20 # Provides a `rustToolchain` attribute for Nixpkgs that we can use to
21 # create a Rust environment
22 (self: super: {
23 rustToolchain = super.rust-bin.stable.latest.default.override {
24 extensions = [ "rust-analyzer" "rust-src" "rust-docs" ];
25 };
26 minimalRustToolchain = super.rust-bin.stable.latest.minimal;
27 })
28 ];
29
30 # Systems supported
31 allSystems = [
32 "x86_64-linux" # 64-bit Intel/AMD Linux
33 #"aarch64-linux" # 64-bit ARM Linux
34 #"x86_64-darwin" # 64-bit Intel macOS
35 #"aarch64-darwin" # 64-bit ARM macOS
36 ];
37
38 # Helper to provide system-specific attributes
39 forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
40 pkgs = import nixpkgs { inherit overlays system; };
41 });
42 in
43 {
44 # Development environment output
45 devShells = forAllSystems ({ pkgs }: {
46 default = pkgs.mkShell {
47 # The Nix packages provided in the environment
48 packages = (with pkgs; [
49 # The package provided by our custom overlay. Includes cargo, Clippy, cargo-fmt,
50 # rustdoc, rustfmt, and other tools.
51 cmake
52 rustToolchain
53 protobuf
54 ]) ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ libiconv ]);
55 };
56 });
57
58 packages = forAllSystems ({ pkgs }: {
59 default = let
60 craneLib = (crane.mkLib pkgs).overrideToolchain pkgs.minimalRustToolchain;
61 commonArgs = {
62 src = pkgs.lib.cleanSourceWith {
63 src = ./.;
64 filter =
65 let
66 protoFilter = path: _type: builtins.match ".*\.proto" path != null;
67 in
68 path: type: (protoFilter path type) || (craneLib.filterCargoSources path type);
69 name = "source";
70 };
71 nativeBuildInputs = with pkgs; [
72 # for one of our rust deps
73 cmake
74 # for building our config
75 protobuf
76 ];
77 };
78 in
79 craneLib.buildPackage ({
80 name = "proxy-in-anger";
81 version = "0.0.1";
82 cargoArtifacts = craneLib.buildDepsOnly commonArgs;
83 meta.mainProgram = "auth-proxy";
84 } // commonArgs);
85 });
86 };
87}