mirror of
https://git.sr.ht/~goorzhel/turboprop
synced 2024-12-14 11:37:37 +00:00
Decouple homelab idiosyncrasies
My long-term vision for this flake is to use it as a control flake: plug it into your homelab ("data-plane") flake and avail yourself of its `lib.builders`, et cetera. In short, I want this flake to be useful to many people, and that means not shipping my homelab with it.
This commit is contained in:
parent
e211b78331
commit
408befb503
11 changed files with 86 additions and 60 deletions
|
@ -38,7 +38,12 @@
|
|||
overlays = [devshell.overlays.default];
|
||||
};
|
||||
kubelib = nix-kube-generators.lib {inherit pkgs;};
|
||||
|
||||
# When I move lib/eureka to a separate flake this'll
|
||||
# look something like:
|
||||
# lib = import ./lib {...} // import ./eureka {...}
|
||||
lib = import ./lib {inherit charts kubelib pkgs;};
|
||||
|
||||
flake-builders = import ./lib/flake-builders.nix {inherit pkgs lib;};
|
||||
|
||||
charts = flake-builders.fetchCharts self.repos;
|
||||
|
|
|
@ -2,25 +2,7 @@
|
|||
charts,
|
||||
kubelib,
|
||||
pkgs,
|
||||
vars,
|
||||
}: let
|
||||
mkSimpleHTTPRoute = namespace: name: port: {
|
||||
service.main.ports.http.port = port;
|
||||
route.main = {
|
||||
enabled = true;
|
||||
hostnames = ["${name}.${vars.svcGateway.domainName}"];
|
||||
parentRefs = [
|
||||
{
|
||||
inherit namespace;
|
||||
name = vars.svcGateway.name;
|
||||
sectionName = "https";
|
||||
}
|
||||
];
|
||||
rules = [
|
||||
{backendRefs = [{inherit name namespace port;}];}
|
||||
];
|
||||
};
|
||||
};
|
||||
in rec {
|
||||
strToImageAttrs = string:
|
||||
with builtins; let
|
||||
|
@ -39,34 +21,17 @@ in rec {
|
|||
namespace,
|
||||
name,
|
||||
mainImage,
|
||||
nfsConfigVolume ? false,
|
||||
httpPort ? false,
|
||||
extraValues ? {},
|
||||
}: let
|
||||
configVolume = {
|
||||
persistence.config =
|
||||
if nfsConfigVolume
|
||||
then mkExistingClaim "svc" name
|
||||
else
|
||||
# TODO: There's room here to chain other types, like
|
||||
# if longhornVolume then {...} else ...
|
||||
{};
|
||||
};
|
||||
httpRoute =
|
||||
if httpPort != false
|
||||
then mkSimpleHTTPRoute namespace name httpPort
|
||||
else {};
|
||||
in
|
||||
values ? {},
|
||||
}:
|
||||
kubelib.buildHelmChart {
|
||||
inherit name namespace;
|
||||
chart = charts.bjw-s.app-template;
|
||||
values =
|
||||
pkgs.lib.attrsets.recursiveUpdate
|
||||
(configVolume
|
||||
// httpRoute
|
||||
// {
|
||||
controllers.main.containers.main.image = strToImageAttrs mainImage;
|
||||
})
|
||||
extraValues;
|
||||
{
|
||||
controllers.main.containers.main.image =
|
||||
strToImageAttrs mainImage;
|
||||
}
|
||||
values; # inf. recursion?
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
kubelib,
|
||||
pkgs,
|
||||
}: rec {
|
||||
appTemplate = import ./app-template.nix {inherit charts kubelib pkgs vars;};
|
||||
appTemplate = import ./app-template.nix {inherit charts kubelib pkgs;};
|
||||
builders = import ./builders.nix {inherit kubelib pkgs;};
|
||||
fetchers = import ./fetchers.nix {inherit kubelib pkgs;};
|
||||
resources = import ./resources.nix {inherit vars;};
|
||||
vars = import ./vars.nix;
|
||||
eureka = import ./eureka {
|
||||
appTemplateLib = appTemplate;
|
||||
inherit pkgs;
|
||||
};
|
||||
}
|
||||
|
|
54
lib/eureka/default.nix
Normal file
54
lib/eureka/default.nix
Normal file
|
@ -0,0 +1,54 @@
|
|||
{
|
||||
appTemplateLib,
|
||||
pkgs,
|
||||
}: let
|
||||
vars = import ./vars.nix;
|
||||
mkSimpleHTTPRoute = namespace: name: port: {
|
||||
service.main.ports.http.port = port;
|
||||
route.main = {
|
||||
enabled = true;
|
||||
hostnames = ["${name}.${vars.svcGateway.domainName}"];
|
||||
parentRefs = [
|
||||
{
|
||||
inherit namespace;
|
||||
name = vars.svcGateway.name;
|
||||
sectionName = "https";
|
||||
}
|
||||
];
|
||||
rules = [
|
||||
{backendRefs = [{inherit name namespace port;}];}
|
||||
];
|
||||
};
|
||||
};
|
||||
in {
|
||||
resources = import ./resources.nix {inherit vars;};
|
||||
inherit vars;
|
||||
|
||||
appTemplate = {
|
||||
namespace,
|
||||
name,
|
||||
mainImage,
|
||||
nfsConfigVolume ? false,
|
||||
httpPort ? false,
|
||||
extraValues ? {},
|
||||
}: let
|
||||
configVolume = {
|
||||
persistence.config =
|
||||
if nfsConfigVolume
|
||||
then appTemplateLib.mkExistingClaim "svc" name
|
||||
else
|
||||
# TODO: There's room here to chain other types, like
|
||||
# if longhornVolume then {...} else ...
|
||||
{};
|
||||
};
|
||||
httpRoute =
|
||||
if httpPort != false
|
||||
then mkSimpleHTTPRoute namespace name httpPort
|
||||
else {};
|
||||
values =
|
||||
pkgs.lib.attrsets.recursiveUpdate
|
||||
(configVolume // httpRoute)
|
||||
extraValues;
|
||||
in
|
||||
appTemplateLib.build {inherit name namespace mainImage values;};
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
{lib}: {
|
||||
builder = lib.appTemplate.build;
|
||||
builder = lib.eureka.appTemplate;
|
||||
args = {
|
||||
mainImage = "quay.io/pussthecatorg/breezewiki:latest";
|
||||
httpPort = 10416;
|
||||
};
|
||||
extraObjects = [
|
||||
(lib.resources.externalServiceEntry "fandom" ["*.fandom.com"])
|
||||
(lib.eureka.resources.externalServiceEntry "fandom" ["*.fandom.com"])
|
||||
];
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{lib}: {
|
||||
builder = lib.appTemplate.build;
|
||||
builder = lib.eureka.appTemplate;
|
||||
args = {
|
||||
mainImage = "linuxserver/calibre-web:0.6.19";
|
||||
nfsConfigVolume = true;
|
||||
|
@ -9,8 +9,8 @@
|
|||
controllers.main.type = "statefulset";
|
||||
controllers.main.containers.main.env = {
|
||||
PGID = "65534"; # nobody
|
||||
PUID = lib.vars.nfsID;
|
||||
TZ = lib.vars.timeZone;
|
||||
PUID = lib.eureka.vars.nfsID;
|
||||
TZ = lib.eureka.vars.timeZone;
|
||||
};
|
||||
|
||||
persistence = {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{lib}: let
|
||||
apiVersion = "gateway.networking.k8s.io/v1beta1";
|
||||
wildcard = "*.${lib.vars.svcGateway.name}.${lib.vars.domain}";
|
||||
wildcard = "*.${lib.eureka.vars.svcGateway.name}.${lib.eureka.vars.domain}";
|
||||
listener = name: protocol: port: hostname: {
|
||||
inherit name protocol port hostname;
|
||||
};
|
||||
|
@ -12,7 +12,7 @@ in {
|
|||
inherit apiVersion;
|
||||
kind = "Gateway";
|
||||
metadata = {
|
||||
name = lib.vars.svcGateway.name;
|
||||
name = lib.eureka.vars.svcGateway.name;
|
||||
annotations."cert-manager.io/cluster-issuer" = "goorzhel-ca";
|
||||
};
|
||||
spec = {
|
||||
|
@ -33,7 +33,7 @@ in {
|
|||
addresses = [
|
||||
{
|
||||
type = "IPAddress";
|
||||
value = lib.vars.svcGateway.ip;
|
||||
value = lib.eureka.vars.svcGateway.ip;
|
||||
}
|
||||
];
|
||||
};
|
||||
|
@ -44,7 +44,7 @@ in {
|
|||
kind = "HTTPRoute";
|
||||
metadata.name = "http-to-https";
|
||||
spec = {
|
||||
parentRefs = lib.vars.svcGateway.parentRef 80;
|
||||
parentRefs = lib.eureka.vars.svcGateway.parentRef 80;
|
||||
hostnames = [wildcard];
|
||||
rules = [
|
||||
{
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
];
|
||||
};
|
||||
in {
|
||||
builder = lib.appTemplate.build;
|
||||
builder = lib.eureka.appTemplate;
|
||||
args = {
|
||||
mainImage = "ghcr.io/onedr0p/jellyfin:10.8.11";
|
||||
httpPort = 8096;
|
||||
|
@ -18,14 +18,14 @@ in {
|
|||
extraValues = {
|
||||
controllers.main.type = "statefulset";
|
||||
controllers.main.containers.main = {
|
||||
env.TZ = lib.vars.timeZone;
|
||||
env.TZ = lib.eureka.vars.timeZone;
|
||||
probes = {
|
||||
readiness.spec.initialDelaySeconds = 15;
|
||||
startup.enabled = false;
|
||||
};
|
||||
securityContext = {
|
||||
runAsUser = lib.vars.nfsID;
|
||||
runAsGroup = lib.vars.nfsID;
|
||||
runAsUser = lib.eureka.vars.nfsID;
|
||||
runAsGroup = lib.eureka.vars.nfsID;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{lib}: {
|
||||
builder = lib.appTemplate.build;
|
||||
builder = lib.eureka.appTemplate;
|
||||
args = {
|
||||
mainImage = "registry.svc.eureka.lan/sota-slack-spotter:latest";
|
||||
|
||||
|
@ -28,6 +28,6 @@
|
|||
};
|
||||
|
||||
extraObjects = [
|
||||
(lib.resources.externalServiceEntry "sota-api" ["api2.sota.org.uk"])
|
||||
(lib.eureka.resources.externalServiceEntry "sota-api" ["api2.sota.org.uk"])
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue