diff --git a/README.rst b/README.rst index aca0160..69b9b58 100644 --- a/README.rst +++ b/README.rst @@ -60,7 +60,10 @@ Add Turboprop to your flake's inputs, along with flake-utils and nixhelm: inputs = { flake-utils.url = "github:numtide/flake-utils"; nixhelm.url = "github:farcaller/nixhelm"; - turboprop.url = "sourcehut:~goorzhel/turboprop"; + turboprop = { + url = "sourcehut:~goorzhel/turboprop"; + inputs.nixhelm.follows = "nixhelm"; + }; }; <...> } @@ -304,6 +307,8 @@ Reference Main functions ============== +These functions are only available outside of service modules. + mkDerivation ------------ @@ -342,12 +347,11 @@ Each module must be an attrset with the signature ``{repo, chart, version, chart mkChartsWithNixhelm ------------------- -``src -> nixhelm -> attrs`` +``src -> attrs`` -Same as ``mkCharts``, but overlays the fetched charts onto the ones `provided by Nixhelm`_. +Same as ``mkCharts``, but overlays the fetched charts onto the ones `provided by Nixhelm`_ through the flake input. - **src** (path): Search root. -- **nixhelm** (attrset): The flake itself. .. _provided by Nixhelm: https://github.com/farcaller/nixhelm/blob/f63710348e393d8640e9e9b896e74bb31a3ee871/flake.nix#L45 diff --git a/flake.lock b/flake.lock index bae0682..1a88dc2 100644 --- a/flake.lock +++ b/flake.lock @@ -18,6 +18,41 @@ "type": "github" } }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "id": "flake-utils", + "type": "indirect" + } + }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "haumea": { "inputs": { "nixpkgs": [ @@ -39,6 +74,28 @@ "type": "github" } }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "nixhelm", + "poetry2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1698974481, + "narHash": "sha256-yPncV9Ohdz1zPZxYHQf47S8S0VrnhV7nNhCawY46hDA=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "4bb5e752616262457bc7ca5882192a564c0472d2", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, "nix-kube-generators": { "locked": { "lastModified": 1708155396, @@ -54,6 +111,44 @@ "type": "github" } }, + "nix-kube-generators_2": { + "locked": { + "lastModified": 1702548734, + "narHash": "sha256-2pREm/iZ1FyyFuukt/B3nud2NYTUImy5vqc2tESoP9g=", + "owner": "farcaller", + "repo": "nix-kube-generators", + "rev": "fb7a70a8cd76aa76fdf3281123582693aec486a7", + "type": "github" + }, + "original": { + "owner": "farcaller", + "repo": "nix-kube-generators", + "type": "github" + } + }, + "nixhelm": { + "inputs": { + "flake-utils": "flake-utils_2", + "nix-kube-generators": "nix-kube-generators_2", + "nixpkgs": [ + "nixpkgs" + ], + "poetry2nix": "poetry2nix" + }, + "locked": { + "lastModified": 1708304289, + "narHash": "sha256-NSM4+RFRDhe+EZtdP8eEpBmaZtXaIDorcqdqYDur3MA=", + "owner": "farcaller", + "repo": "nixhelm", + "rev": "5b0db2c7db259e0b4d3abb281e7c51111e2921bc", + "type": "github" + }, + "original": { + "owner": "farcaller", + "repo": "nixhelm", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1701669346, @@ -69,11 +164,37 @@ "type": "github" } }, + "poetry2nix": { + "inputs": { + "flake-utils": "flake-utils_3", + "nix-github-actions": "nix-github-actions", + "nixpkgs": [ + "nixhelm", + "nixpkgs" + ], + "systems": "systems_4", + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1702365004, + "narHash": "sha256-IRFvmyP1uk1hchRVxaXTqu6YoZCvMM/NVtUf2hD2Tag=", + "owner": "nix-community", + "repo": "poetry2nix", + "rev": "c12ac880114d52a3cad5fa02b00f2e2090e89982", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "poetry2nix", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", "haumea": "haumea", "nix-kube-generators": "nix-kube-generators", + "nixhelm": "nixhelm", "nixpkgs": "nixpkgs" } }, @@ -91,6 +212,72 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_4": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "id": "systems", + "type": "indirect" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixhelm", + "poetry2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1699786194, + "narHash": "sha256-3h3EH1FXQkIeAuzaWB+nK0XK54uSD46pp+dMD3gAcB4=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "e82f32aa7f06bbbd56d7b12186d555223dc399d1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 42c0cea..7d27f45 100644 --- a/flake.nix +++ b/flake.nix @@ -9,6 +9,10 @@ inputs.nixpkgs.follows = "nixpkgs"; }; nix-kube-generators.url = "github:farcaller/nix-kube-generators"; + nixhelm = { + url = "github:farcaller/nixhelm"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = inputs @ { @@ -17,6 +21,7 @@ haumea, nix-kube-generators, nixpkgs, + nixhelm, }: { templates.default = { @@ -27,6 +32,7 @@ // flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs {inherit system;}; kubelib = nix-kube-generators.lib {inherit pkgs;}; + nixhelmCharts = nixhelm.chartsDerivations.${system}; lib = import ./lib {inherit kubelib pkgs;}; mkCharts = src: @@ -36,7 +42,7 @@ transformer = haumea.lib.transformers.liftDefault; }; in { - lib = { + lib = lib // { mkDerivation = { charts, user ? {}, @@ -46,12 +52,10 @@ }) .mkDerivation; - app-template = lib.app-template; - inherit mkCharts; - mkChartsWithNixhelm = src: nh: + mkChartsWithNixhelm = src: pkgs.lib.attrsets.recursiveUpdate - nh.chartsDerivations.${system} + nixhelmCharts (mkCharts src); }; diff --git a/lib/app-template/default.nix b/lib/app-template.nix similarity index 83% rename from lib/app-template/default.nix rename to lib/app-template.nix index dc92ea5..1e78b06 100644 --- a/lib/app-template/default.nix +++ b/lib/app-template.nix @@ -1,11 +1,7 @@ { builders, - fetchers, pkgs, -}: let - bundledATChart = fetchers.helmChart (import ./chart.nix); -in - rec { +}: rec { mkImageAttrs = image: with builtins; let vals = pkgs.lib.strings.splitString ":" image; @@ -41,14 +37,13 @@ in namespace, name, mainImage, - appTemplateChart ? bundledATChart, + chart, values ? {}, kubeVersion ? pkgs.kubernetes.version, apiVersions ? [], }: builders.helmChart { - inherit name namespace kubeVersion apiVersions; - chart = appTemplateChart; + inherit name namespace chart kubeVersion apiVersions; values = pkgs.lib.attrsets.recursiveUpdate { diff --git a/lib/app-template/chart.nix b/lib/app-template/chart.nix deleted file mode 100644 index 8bce114..0000000 --- a/lib/app-template/chart.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - repo = "https://bjw-s.github.io/helm-charts/"; - chart = "app-template"; - version = "2.3.0"; - chartHash = "sha256-J0hWCLYyeVIiIJcFOCt5Oq0IubzFw3Bs61TWWuVOvYU="; -} diff --git a/lib/default.nix b/lib/default.nix index f14e7ad..1c6bcc8 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -4,7 +4,7 @@ }: rec { builders = import ./builders.nix {inherit kubelib pkgs;}; fetchers = import ./fetchers.nix {inherit kubelib pkgs;}; - app-template = import ./app-template {inherit builders fetchers pkgs;}; + app-template = import ./app-template.nix {inherit builders pkgs;}; parseYAMLsFile = p: kubelib.fromYAML (builtins.readFile p); parseYAMLFile = p: builtins.head (parseYAMLsFile p); diff --git a/templates/default/flake.nix b/templates/default/flake.nix index 3305787..5961c33 100644 --- a/templates/default/flake.nix +++ b/templates/default/flake.nix @@ -9,6 +9,7 @@ turboprop = { url = "sourcehut:~goorzhel/turboprop"; inputs.nixpkgs.follows = "nixpkgs"; + inputs.nixhelm.follows = "nixhelm"; }; };