Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pod support #6

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ Compared to alternatives like [`virtualisation.oci-containers`](https://github.c
containers = {
nginx.containerConfig.image = "docker.io/library/nginx:latest";
nginx.containerConfig.networks = [ "host" "internal.network" ];
nginx.containerConfig.pod = "nginx-pod.pod";
nginx.serviceConfig.TimeoutStartSec = "60";
};
networks = {
internal.networkConfig.subnets = [ "10.0.123.1/24" ];
};
pods = {
nginx-pod = { };
};
};
}
```

See [`container.nix`](./container.nix) and [`network.nix`](./network.nix) for all options.
See [`container.nix`](./container.nix), [`network.nix`](./network.nix), and [`pod.nix`](./pod.nix) for all options.
88 changes: 55 additions & 33 deletions container.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{ quadletUtils }:
{ config, name, lib, ... }:

{
config,
name,
lib,
...
}:
with lib;

let
containerOpts = {
addCapabilities = quadletUtils.mkOption {
Expand Down Expand Up @@ -30,7 +33,12 @@ let
};

autoUpdate = quadletUtils.mkOption {
type = types.nullOr (types.enum [ "registry" "local" ]);
type = types.nullOr (
types.enum [
"registry"
"local"
]
);
default = null;
example = "registry";
description = "--label \"io.containers.autoupdate=...\"";
Expand All @@ -56,7 +64,9 @@ let
environments = quadletUtils.mkOption {
type = types.attrs;
default = { };
example = { foo = "bar"; };
example = {
foo = "bar";
};
description = "--env";
property = "Environment";
};
Expand Down Expand Up @@ -91,7 +101,7 @@ let
description = "--expose";
property = "ExposeHostPort";
};

group = quadletUtils.mkOption {
type = types.nullOr types.str;
default = null;
Expand Down Expand Up @@ -210,7 +220,7 @@ let
description = "--ip";
property = "IP";
};

ip6 = quadletUtils.mkOption {
type = types.nullOr types.str;
default = null;
Expand Down Expand Up @@ -242,12 +252,12 @@ let
description = "--mount";
property = "Mount";
};

networks = quadletUtils.mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "host" ];
description = "--network";
description = "--net";
property = "Network";
};

Expand All @@ -273,6 +283,13 @@ let
property = "Notify";
};

pod = quadletUtils.mkOption {
type = types.nullOr types.str;
default = null;
description = "The full name of the pod to link to.";
property = "Pod";
};

podmanArgs = quadletUtils.mkOption {
type = types.listOf types.str;
default = [ ];
Expand Down Expand Up @@ -376,7 +393,9 @@ let
sysctl = quadletUtils.mkOption {
type = types.attrs;
default = { };
example = { name = "value"; };
example = {
name = "value";
};
description = "--sysctl";
property = "Sysctl";
};
Expand Down Expand Up @@ -441,7 +460,8 @@ let
Restart = "always";
TimeoutStartSec = 900;
};
in {
in
{
options = {
autoStart = mkOption {
type = types.bool;
Expand All @@ -452,38 +472,40 @@ in {
containerConfig = containerOpts;
unitConfig = mkOption {
type = types.attrs;
default = {};
default = { };
};
serviceConfig = mkOption {
type = types.attrs;
default = serviceConfigDefault;
};

_name = mkOption { internal = true; };
_configName = mkOption { internal = true; };
_unitName = mkOption { internal = true; };
_configText = mkOption { internal = true; };
};

config = let
configRelPath = "containers/systemd/${name}.container";
containerName = if config.containerConfig.name != null
then config.containerConfig.name
else name;
containerConfig = config.containerConfig // { name = containerName; };
unitConfig = {
Unit = {
Description = "Podman container ${name}";
} // config.unitConfig;
Install = {
WantedBy = if config.autoStart then [ "default.target" ] else [];
config =
let
containerName = if config.containerConfig.name != null then config.containerConfig.name else name;
containerConfig = config.containerConfig // {
name = containerName;
};
Container = quadletUtils.configToProperties containerConfig containerOpts;
Service = serviceConfigDefault // config.serviceConfig;
};
unitConfigText = quadletUtils.unitConfigToText unitConfig;
in {
_configName = "${name}.container";
_unitName = "${name}.service";
_configText = quadletUtils.unitConfigToText unitConfig;
};
unitConfig = {
Unit = {
Description = "Podman container ${name}";
} // config.unitConfig;
Install = {
WantedBy = if config.autoStart then [ "default.target" ] else [ ];
};
Container = quadletUtils.configToProperties containerConfig containerOpts;
Service = serviceConfigDefault // config.serviceConfig;
};
in
{
_name = containerName;
_configName = "${name}.container";
_unitName = "${name}.service";
_configText = quadletUtils.unitConfigToText unitConfig;
};
}
14 changes: 8 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};

outputs = { nixpkgs, ... }:
let
libUtils = import "${nixpkgs}/nixos/lib/utils.nix";
in {
nixosModules.quadlet = import ./nixos-module.nix { inherit libUtils; };
};
outputs =
{ nixpkgs, ... }:
let
libUtils = import "${nixpkgs}/nixos/lib/utils.nix";
in
{
nixosModules.quadlet = import ./nixos-module.nix { inherit libUtils; };
};
}
83 changes: 52 additions & 31 deletions network.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{ quadletUtils, pkgs }:
{ config, name, lib, ... }:

{
quadletUtils,
pkgs,
}:
{
config,
name,
lib,
...
}:
with lib;

let
networkOpts = {
disableDns = quadletUtils.mkOption {
Expand All @@ -13,7 +19,13 @@ let
};

driver = quadletUtils.mkOption {
type = types.nullOr (types.enum [ "bridge" "macvlan" "ipvlan" ]);
type = types.nullOr (
types.enum [
"bridge"
"macvlan"
"ipvlan"
]
);
default = null;
example = "bridge";
description = "--driver";
Expand All @@ -36,7 +48,13 @@ let
};

ipamDriver = quadletUtils.mkOption {
type = types.nullOr (types.enum [ "host-local" "dhcp" "none" ]);
type = types.nullOr (
types.enum [
"host-local"
"dhcp"
"none"
]
);
default = null;
example = "dhcp";
description = "--ipam-driver";
Expand Down Expand Up @@ -98,7 +116,8 @@ let
property = "Subnet";
};
};
in {
in
{
options = {
autoStart = mkOption {
type = types.bool;
Expand All @@ -109,39 +128,41 @@ in {
networkConfig = networkOpts;
unitConfig = mkOption {
type = types.attrs;
default = {};
default = { };
};
serviceConfig = mkOption {
type = types.attrs;
default = {};
default = { };
};

_configName = mkOption { internal = true; };
_name = mkOption { internal = true; };
_unitName = mkOption { internal = true; };
_configText = mkOption { internal = true; };
};

config = let
configRelPath = "containers/systemd/${name}.network";
networkName = if config.networkConfig.name != null
then config.networkConfig.name
else "systemd-${name}";
networkConfig = config.networkConfig;
unitConfig = {
Unit = {
Description = "Podman network ${name}";
} // config.unitConfig;
Install = {
WantedBy = if config.autoStart then [ "default.target" ] else [];
config =
let
networkName =
if config.networkConfig.name != null then config.networkConfig.name else "systemd-${name}";
networkConfig = config.networkConfig;
unitConfig = {
Unit = {
Description = "Podman network ${name}";
} // config.unitConfig;
Install = {
WantedBy = if config.autoStart then [ "default.target" ] else [ ];
};
Network = quadletUtils.configToProperties networkConfig networkOpts;
Service = {
ExecStop = "${pkgs.podman}/bin/podman network rm ${networkName}";
} // config.serviceConfig;
};
Network = quadletUtils.configToProperties networkConfig networkOpts;
Service = {
ExecStop = "${pkgs.podman}/bin/podman network rm ${networkName}";
} // config.serviceConfig;
};
in {
_configName = "${name}.network";
_unitName = "${name}-network.service";
_configText = quadletUtils.unitConfigToText unitConfig;
};
in
{
_name = networkName;
_configName = "${name}.network";
_unitName = "${name}-network.service";
_configText = quadletUtils.unitConfigToText unitConfig;
};
}
Loading