Create helper function to create NixNG images

Move NixNG images to separate directory
This commit is contained in:
Pim Kunis 2024-10-01 22:51:08 +02:00
parent e3ff293c0c
commit 8e09ef5c1e
6 changed files with 31 additions and 39 deletions

View file

@ -11,9 +11,15 @@ inputs@{ self, servers, flutils, nixpkgs, kubenix, ... }: flutils.lib.eachDefaul
mkKubernetes = name: module: namespace: (kubenix.evalModules.${system} {
specialArgs = {
inherit namespace system machines;
inherit namespace system machines self;
inherit (inputs) nixhelm blog-pim dns nixpkgs nixng;
inherit (self) globals;
utils = import ./utils.nix {
inherit pkgs;
inherit (inputs) nixpkgs nixng;
inherit (self) globals;
};
};
module = { kubenix, ... }:
@ -57,7 +63,7 @@ inputs@{ self, servers, flutils, nixpkgs, kubenix, ... }: flutils.lib.eachDefaul
k8sMachines = lib.filterAttrs (n: m: m.kubernetesNodeLabels != null) machines;
k8sServerNames = builtins.concatStringsSep " " (builtins.attrNames k8sMachines);
in
''
/* bash */ ''
wrapProgram $out/bin/applyset-deploy.sh \
--suffix PATH : "$out/bin" \
--run 'export KUBECONFIG=''${KUBECONFIG:-${toString kubeconfig}}' \

View file

@ -1,21 +1,4 @@
{ nixpkgs, pkgs, lib, nixng, config, globals, ... }:
let
atticStream = (import ./attic-image.nix {
inherit nixpkgs nixng globals;
inherit (nixng) nglib;
}).config.system.build.ociImage.stream;
atticImage = pkgs.stdenv.mkDerivation {
name = "attic.tar";
src = atticStream;
dontUnpack = true;
buildPhase = ''
$src > $out
'';
};
in
{
{ self, utils, lib, config, globals, ... }: {
options.attic.enable = lib.mkEnableOption "attic";
config = lib.mkIf config.attic.enable {
@ -52,7 +35,7 @@ in
spec = {
containers.attic = {
image = "nix:0${atticImage}";
image = utils.nixSnapshotterRef (utils.mkNixNGImage "attic" "${self}/images/attic.nix");
ports.web.containerPort = 8080;
env = {

View file

@ -1,20 +1,4 @@
{ nixpkgs, pkgs, nixng, globals, config, lib, ... }:
let
dnsmasqStream = (import ./dnsmasq-image.nix {
inherit nixpkgs nixng globals;
inherit (nixng) nglib;
}).config.system.build.ociImage.stream;
dnsmasqImage = pkgs.stdenv.mkDerivation {
name = "dnsmasq.tar";
src = dnsmasqStream;
dontUnpack = true;
buildPhase = ''
$src > $out
'';
};
in
{
{ self, utils, globals, config, lib, ... }: {
options.dnsmasq.enable = lib.mkEnableOption "dnsmasq";
config = lib.mkIf config.dnsmasq.enable {
@ -26,7 +10,7 @@ in
metadata.labels.app = "dnsmasq";
spec.containers.dnsmasq = {
image = "nix:0${dnsmasqImage}";
image = utils.nixSnapshotterRef (utils.mkNixNGImage "dnsmasq" "${self}/images/dnsmasq.nix");
imagePullPolicy = "Always";
ports.dns = {

19
utils.nix Normal file
View file

@ -0,0 +1,19 @@
{ pkgs, nixpkgs, nixng, globals, ... }: {
mkNixNGImage = name: file:
let
stream = (import file {
inherit nixpkgs nixng globals;
inherit (nixng) nglib;
}).config.system.build.ociImage.stream;
in
pkgs.stdenv.mkDerivation {
name = "${name}.tar";
src = stream;
dontUnpack = true;
buildPhase = ''
$src > $out
'';
};
nixSnapshotterRef = imagePath: "nix:0${imagePath}";
}