1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-03-31 04:04:32 +00:00

podman: fix service name in generated manifest (#6710)

This commit is contained in:
Tarow 2025-03-30 01:50:46 +01:00 committed by GitHub
parent b431496538
commit 7170300119
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,18 +1,16 @@
{ pkgs, lib, config, ... }: { pkgs, lib, config, ... }:
with lib; with lib;
let let
normalizeKeyValue = k: v: normalizeKeyValue = k: v:
let let
v' = (if builtins.isBool v then v' = if builtins.isBool v then
(if v then "true" else "false") (if v then "true" else "false")
else if builtins.isAttrs v then else if builtins.isAttrs v then
(concatStringsSep '' (concatStringsSep ''
${k}='' (mapAttrsToList normalizeKeyValue v)) ${k}='' (mapAttrsToList normalizeKeyValue v))
else else
builtins.toString v); builtins.toString v;
in if builtins.isNull v then "" else "${k}=${v'}"; in if builtins.isNull v then "" else "${k}=${v'}";
primitiveAttrs = with types; attrsOf (either primitive (listOf primitive)); primitiveAttrs = with types; attrsOf (either primitive (listOf primitive));
@ -32,9 +30,9 @@ let
bVal = if builtins.hasAttr key b then b.${key} else null; bVal = if builtins.hasAttr key b then b.${key} else null;
# check if the types inside a list match the type of a primitive # check if the types inside a list match the type of a primitive
listMatchesType = (list: val: listMatchesType = list: val:
isList list && builtins.length list > 0 isList list && builtins.length list > 0
&& builtins.typeOf (builtins.head list) == builtins.typeOf val); && builtins.typeOf (builtins.head list) == builtins.typeOf val;
in if isAttrs aVal && isAttrs bVal then in if isAttrs aVal && isAttrs bVal then
result // { ${key} = deepMerge aVal bVal; } result // { ${key} = deepMerge aVal bVal; }
else if isList aVal && isList bVal then else if isList aVal && isList bVal then
@ -63,7 +61,7 @@ in {
buildConfigAsserts = quadletName: extraConfig: buildConfigAsserts = quadletName: extraConfig:
let let
configRules = { configRules = {
Build = { ImageTag = (with types; listOf str); }; Build = { ImageTag = with types; listOf str; };
Container = { ContainerName = types.enum [ quadletName ]; }; Container = { ContainerName = types.enum [ quadletName ]; };
Network = { NetworkName = types.enum [ quadletName ]; }; Network = { NetworkName = types.enum [ quadletName ]; };
Volume = { VolumeName = types.enum [ quadletName ]; }; Volume = { VolumeName = types.enum [ quadletName ]; };
@ -96,7 +94,6 @@ in {
message = '' message = ''
In '${quadletName}' config. Build.ImageTag: '[ "${imageTagsStr}" ]' does not contain 'homemanager/${quadletName}'.''; In '${quadletName}' config. Build.ImageTag: '[ "${imageTagsStr}" ]' does not contain 'homemanager/${quadletName}'.'';
}]; }];
# Flatten assertions from all sections in `extraConfig`. # Flatten assertions from all sections in `extraConfig`.
in flatten (concatLists [ in flatten (concatLists [
(mapAttrsToList buildSectionAsserts extraConfig) (mapAttrsToList buildSectionAsserts extraConfig)
@ -119,8 +116,7 @@ in {
formatServiceName = quadlet: formatServiceName = quadlet:
let let
# remove the podman- prefix from the service name string # remove the podman- prefix from the service name string
strippedName = strippedName = lib.removePrefix "podman-" quadlet.serviceName;
builtins.replaceStrings [ "podman-" ] [ "" ] quadlet.serviceName;
# specific logic for writing the unit name goes here. It should be # specific logic for writing the unit name goes here. It should be
# identical to what `podman <resource> ls` shows # identical to what `podman <resource> ls` shows
in { in {