Changed option namespace for better compatibility
This commit is contained in:
parent
fe8045ee55
commit
8b25f46384
26 changed files with 407 additions and 232 deletions
|
|
@ -6,6 +6,5 @@
|
|||
./lxc-guest.nix
|
||||
./podman.nix
|
||||
./podman-pod.nix
|
||||
./proxmox.nix
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@
|
|||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.docker;
|
||||
cfg = config.my.virtualisation.docker;
|
||||
in
|
||||
{
|
||||
options.docker = {
|
||||
options.my.virtualisation.docker = {
|
||||
enable = lib.mkEnableOption "Enable Docker module";
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@
|
|||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.libvirtd;
|
||||
cfg = config.my.virtualisation.libvirtd;
|
||||
in
|
||||
{
|
||||
options.libvirtd = {
|
||||
options.my.virtualisation.libvirtd = {
|
||||
enable = lib.mkEnableOption "Enable libvirtd module";
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
{ config, lib, ... }:
|
||||
let
|
||||
cfg = config.lxcGuest;
|
||||
cfg = config.my.virtualisation.lxcGuest;
|
||||
in
|
||||
{
|
||||
options.lxcGuest = {
|
||||
options.my.virtualisation.lxcGuest = {
|
||||
enable = lib.mkEnableOption "NixOs inside LXC container";
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@
|
|||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.lxc;
|
||||
cfg = config.my.virtualisation.lxc;
|
||||
in
|
||||
{
|
||||
options.lxc = {
|
||||
options.my.virtualisation.lxc = {
|
||||
enable = lib.mkEnableOption "Enable LXC module";
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
# Save this as podman-pod.nix
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
|
|
@ -9,44 +8,67 @@
|
|||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.podmanPods;
|
||||
cfg = config.my.virtualisation.podmanPods;
|
||||
|
||||
# Get the options from the original oci-containers module
|
||||
containerOptions = (
|
||||
filterAttrs (
|
||||
n: v: n != "definition"
|
||||
) config.virtualisation.oci-containers.containers.type.getSubOptions
|
||||
);
|
||||
# containerOptions = (
|
||||
# filterAttrs (
|
||||
# n: v: n != "definition"
|
||||
# ) config.virtualisation.oci-containers.containers.type.getSubOptions
|
||||
# );
|
||||
|
||||
# containerDefinition = mkOption {
|
||||
# type = types.attrs;
|
||||
# description = "The container definition, derived from virtualisation.oci-containers.containers.";
|
||||
# example = {
|
||||
# image = "nginx:latest";
|
||||
# ports = [ "8080:80" ];
|
||||
# };
|
||||
# default = { };
|
||||
# };
|
||||
|
||||
# containerDefinition = mkOption {
|
||||
# type = types.attrs;
|
||||
# description = "The container definition, derived from virtualisation.oci-containers.containers.";
|
||||
# example = {
|
||||
# image = "nginx:latest";
|
||||
# ports = [ "8080:80" ];
|
||||
# };
|
||||
# default = {};
|
||||
|
||||
# };
|
||||
# # config.virtualisation.oci-containers.containers.type.getSubOptions;
|
||||
|
||||
containerDefinition = config.virtualisation.oci-containers.containers.type.getSubOptions;
|
||||
|
||||
# Add our enable option
|
||||
extendedContainerOptions = containerOptions // {
|
||||
extendedContainerOptions = containerDefinition // {
|
||||
enable = mkEnableOption "Enable this container";
|
||||
};
|
||||
|
||||
podOptions =
|
||||
{ name, config, ... }:
|
||||
{
|
||||
options = {
|
||||
podOptions = {
|
||||
options = with types; {
|
||||
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
description = "Name of the pod";
|
||||
};
|
||||
name = mkOption {
|
||||
type = str;
|
||||
description = "Name of the pod";
|
||||
};
|
||||
|
||||
ports = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "List of port mappings (e.g. ['8080:80'])";
|
||||
};
|
||||
|
||||
containers = mkOption {
|
||||
type = types.attrsOf (types.submodule { options = extendedContainerOptions; });
|
||||
default = { };
|
||||
description = "Attribute set of OCI container configurations for this set";
|
||||
};
|
||||
ports = mkOption {
|
||||
type = listOf str;
|
||||
default = [ ];
|
||||
description = "List of port mappings (e.g. ['8080:80'])";
|
||||
};
|
||||
|
||||
containers = mkOption {
|
||||
type = attrsOf (submodule {
|
||||
options = extendedContainerOptions;
|
||||
});
|
||||
default = { };
|
||||
description = "Attribute set of OCI container configurations for this set";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
createPodScript =
|
||||
name: podDef:
|
||||
|
|
@ -82,27 +104,49 @@ let
|
|||
fi
|
||||
'';
|
||||
|
||||
enabledContainers = lib.flatten (
|
||||
mapAttrs (
|
||||
podName: podConfig: filterAttrs (name: value: value.enable or true) podConfig.containers
|
||||
) cfg
|
||||
);
|
||||
# enabledContainers = lib.flatten (
|
||||
# mapAttrs (
|
||||
# podName: podConfig: filterAttrs (name: value: value.enable or true) podConfig.containers
|
||||
# ) cfg
|
||||
# );
|
||||
|
||||
# flattenPodContainers =
|
||||
# pods:
|
||||
# mapAttrs' (
|
||||
# podName: pod:
|
||||
# mapAttrs' (
|
||||
# containerName: container:
|
||||
# nameValuePair "${podName}-${containerName}" (
|
||||
# container
|
||||
# # // {
|
||||
# # inherit (pod) name;
|
||||
# # extraOptions = (container.extraOptions or [ ]) ++ [ "--pod=${pod.name}" ];
|
||||
# # }
|
||||
# )
|
||||
# ) (filterAttrs (n: v: v.enable or true) pod.containers)
|
||||
# ) pods;
|
||||
|
||||
in
|
||||
{
|
||||
options.services.podmanPods = mkOption {
|
||||
options.my.virtualisation.podmanPods = mkOption {
|
||||
type = types.attrsOf (types.submodule podOptions);
|
||||
default = { };
|
||||
description = "Podman pods to create";
|
||||
};
|
||||
|
||||
config = mkIf (cfg != { }) {
|
||||
virtualisation.podman.enable = true;
|
||||
virtualisation.oci-containers.backend = "podman";
|
||||
|
||||
my.virtualisation.podman.enable = true;
|
||||
|
||||
environment.systemPackages = [ pkgs.jq ];
|
||||
|
||||
virtualisation.oci-containers.containers = enabledContainers;
|
||||
# virtualisation.oci-containers.containers = enabledContainers;
|
||||
|
||||
# virtualisation.oci-containers.containers = flattenPodContainers cfg;
|
||||
|
||||
# virtualisation.oci-containers.containers = lib.mkMerge (
|
||||
# map (entry: entry.container) (filter (entry: entry.enable) cfg.containers)
|
||||
# );
|
||||
|
||||
# virtualisation.oci-containers.containers = listToAttrs (flatten (mapAttrsToList
|
||||
# (podName: podDef:
|
||||
|
|
@ -159,6 +203,7 @@ in
|
|||
wantedBy = [ "multi-user.target" ];
|
||||
}
|
||||
) cfg;
|
||||
|
||||
containerServices = mapAttrs' (
|
||||
name: container:
|
||||
nameValuePair "podman-${name}" {
|
||||
|
|
@ -166,8 +211,9 @@ in
|
|||
requires = [ "podman-pod-${lib.head (lib.splitString "-" name)}.service" ];
|
||||
partOf = [ "podman-pod-${lib.head (lib.splitString "-" name)}.service" ];
|
||||
}
|
||||
) config.virtualisation.oci-containers.containers;
|
||||
) config.containers;
|
||||
in
|
||||
podServices // containerServices;
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@
|
|||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.podman;
|
||||
cfg = config.my.virtualisation.podman;
|
||||
in
|
||||
{
|
||||
options.podman = {
|
||||
options.my.virtualisation.podman = {
|
||||
enable = lib.mkEnableOption "Enable Podman module";
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,15 +2,16 @@
|
|||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cfg = config.proxmox;
|
||||
cfg = config.my.virtualisation.proxmox;
|
||||
in
|
||||
{
|
||||
|
||||
options.proxmox = {
|
||||
options.my.virtualisation.proxmox = {
|
||||
enable = lib.mkEnableOption "If this host is running inside Proxmox";
|
||||
|
||||
privileged = lib.mkOption {
|
||||
|
|
@ -50,7 +51,7 @@ in
|
|||
manageHostName = cfg.manageHostName;
|
||||
};
|
||||
|
||||
serverNodeUsers.enable = true;
|
||||
my.utils.serverNodeUsers.enable = true;
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue