nix fmt with "nixfmt-rfc-style"

This commit is contained in:
pazpi 2024-08-27 09:46:44 +02:00
parent 4a39b2cbfd
commit eb9f742b1e
26 changed files with 460 additions and 267 deletions

View file

@ -1,5 +1,10 @@
# Save this as podman-pod.nix
{ config, lib, pkgs, ... }:
{
config,
lib,
pkgs,
...
}:
with lib;
@ -7,40 +12,44 @@ let
cfg = config.services.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
);
# Add our enable option
extendedContainerOptions = containerOptions // {
enable = mkEnableOption "Enable this container";
};
podOptions = { name, config, ... }: {
options = {
podOptions =
{ name, config, ... }:
{
options = {
name = mkOption {
type = types.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";
};
name = mkOption {
type = types.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";
};
};
};
createPodScript = name: podDef:
createPodScript =
name: podDef:
let
podDefinitionString = builtins.toJSON { inherit (podDef) ports; };
in
@ -73,11 +82,11 @@ 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
);
in
{
@ -126,37 +135,38 @@ in
# )
# (filterAttrs (name: value: value.enable) cfg.containers);
networking.firewall.allowedTCPPorts = flatten (mapAttrsToList
(name: podDef:
map (portMapping: lib.toInt (lib.head (lib.splitString ":" portMapping))) podDef.ports
)
cfg);
networking.firewall.allowedTCPPorts = flatten (
mapAttrsToList (
name: podDef: map (portMapping: lib.toInt (lib.head (lib.splitString ":" portMapping))) podDef.ports
) cfg
);
systemd.services =
let
podServices = mapAttrs'
(name: podDef:
nameValuePair "podman-pod-${name}" {
description = "Manage Podman pod: ${name}";
serviceConfig = {
Type = "oneshot";
ExecStart = "${createPodScript name podDef}";
};
path = [ pkgs.jq pkgs.podman ];
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
}
)
cfg;
containerServices = mapAttrs'
(name: container:
nameValuePair "podman-${name}" {
after = [ "podman-pod-${lib.head (lib.splitString "-" name)}.service" ];
requires = [ "podman-pod-${lib.head (lib.splitString "-" name)}.service" ];
partOf = [ "podman-pod-${lib.head (lib.splitString "-" name)}.service" ];
}
)
config.virtualisation.oci-containers.containers;
podServices = mapAttrs' (
name: podDef:
nameValuePair "podman-pod-${name}" {
description = "Manage Podman pod: ${name}";
serviceConfig = {
Type = "oneshot";
ExecStart = "${createPodScript name podDef}";
};
path = [
pkgs.jq
pkgs.podman
];
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
}
) cfg;
containerServices = mapAttrs' (
name: container:
nameValuePair "podman-${name}" {
after = [ "podman-pod-${lib.head (lib.splitString "-" name)}.service" ];
requires = [ "podman-pod-${lib.head (lib.splitString "-" name)}.service" ];
partOf = [ "podman-pod-${lib.head (lib.splitString "-" name)}.service" ];
}
) config.virtualisation.oci-containers.containers;
in
podServices // containerServices;
};