
Adds a new Podman module for creating user containers and networks as systemd services. These are installed to the user's XDG_CONFIG/systemd/user directory.
58 lines
1.5 KiB
Nix
58 lines
1.5 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
podman-lib = import ./podman-lib.nix { inherit lib; };
|
|
|
|
createQuadletSource = name: networkDef:
|
|
''
|
|
# Automatically generated by home-manager for podman network configuration
|
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
[Network]
|
|
Label=nix.home-manager.managed=true
|
|
${podman-lib.formatExtraConfig networkDef}
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target default.target
|
|
|
|
[Service]
|
|
Environment="PATH=${pkgs.shadow}"
|
|
'';
|
|
|
|
toQuadletInternal = name: networkDef:
|
|
{
|
|
serviceName = "podman-${name}"; # becomes podman-<netname>-network.service because of quadlet
|
|
source = createQuadletSource name networkDef;
|
|
unitType = "network";
|
|
};
|
|
|
|
in
|
|
{
|
|
options = {
|
|
services.podman.networks = mkOption {
|
|
type = types.attrsOf (podman-lib.primitiveAttrs);
|
|
default = {};
|
|
example = literalExample ''
|
|
{
|
|
mynetwork = {
|
|
Subnet = "192.168.1.0/24";
|
|
Gateway = "192.168.1.1";
|
|
NetworkName = "mynetwork";
|
|
};
|
|
}
|
|
'';
|
|
description = "Defines Podman network quadlet configurations.";
|
|
};
|
|
};
|
|
|
|
config = let
|
|
networkQuadlets = mapAttrsToList toQuadletInternal config.services.podman.networks;
|
|
in {
|
|
internal.podman-quadlet-definitions = networkQuadlets;
|
|
|
|
# manifest file
|
|
home.file."${config.xdg.configHome}/podman/networks.manifest".text = podman-lib.generateManifestText networkQuadlets;
|
|
};
|
|
}
|