Skip to content

Instantly share code, notes, and snippets.

@maxsei
Last active March 3, 2026 14:31
Show Gist options
  • Select an option

  • Save maxsei/4a739569e0c909606fe02eae43500013 to your computer and use it in GitHub Desktop.

Select an option

Save maxsei/4a739569e0c909606fe02eae43500013 to your computer and use it in GitHub Desktop.
# nix-kube-generators.url = "github:farcaller/nix-kube-generators";
# ...
# pkgs = import nixpkgs {
# inherit system;
# overlays = [
# (final: prev: {
# lib = prev.lib.extend (
# _: _: {
# kube = nix-kube-generators.lib { pkgs = final; };
# }
# );
# })
# ];
# };
{ pkgs, lib }:
let
longhorn-helm = lib.kube.buildHelmChart {
name = "longhorn";
namespace = "longhorn-system";
chart = lib.kube.downloadHelmChart {
repo = "https://charts.longhorn.io";
chart = "longhorn";
version = "1.11.0";
chartHash = "sha256-s1UBZTlU/AW6ZQmqN9wiQOA76uoWgCBGhenn9Hx3DCQ=";
};
values = {
defaultSettings = {
defaultReplicaCount = 2;
defaultDataPath = "/var/lib/longhorn";
};
persistence = {
defaultClass = true;
defaultClassReplicaCount = 2;
};
service.ui.type = "ClusterIP";
longhornManager.resources = {
requests = {
cpu = "100m";
memory = "128Mi";
};
limits = {
cpu = "200m";
memory = "256Mi";
};
};
};
};
longhorn-resources = map lib.kube.toYAMLFile [
{
apiVersion = "v1";
kind = "Namespace";
metadata.name = "longhorn-system";
}
{
apiVersion = "networking.k8s.io/v1";
kind = "IngressRoute";
metadata.name = "longhorn-frontend-ingress-route";
spec = {
entryPoints = [ "websecure" ];
routes = [
{
kind = "Rule";
match = "Host(`longhorn.home.lan`)";
services = [
{
name = "longhorn-frontend";
port = 80;
}
];
}
];
};
}
];
in
pkgs.runCommand ""
{
paths = map builtins.toString ([ longhorn-helm ] ++ longhorn-resources);
}
''
${pkgs.yq-go}/bin/yq eval '.metadata.labels."app.kubernetes.io/managed-by" = "nix"' $paths > tmp.yaml
mkdir $out
${pkgs.yq-go}/bin/yq 'select(.kind == "CustomResourceDefinition")' tmp.yaml > $out/crds.yaml
${pkgs.yq-go}/bin/yq 'select(.kind == "Namespace")' tmp.yaml > $out/namespaces.yaml
${pkgs.yq-go}/bin/yq 'select(.kind != "Namespace" and .kind != "CustomResourceDefinition")' $paths > $out/manifests.yaml
''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment