mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-04-25 18:19:10 +00:00
programs/distrobox: improve quoting for generated settings
This commit is contained in:
parent
7a61b28902
commit
af54c3570a
@ -3,6 +3,9 @@
|
||||
let
|
||||
cfg = config.programs.distrobox;
|
||||
|
||||
# Since it's in POSIX sh so we'll quote everything as much as possible.
|
||||
# Ideally, we'll go with single-quoted strings but this prevents dynamic
|
||||
# values with shell expansions.
|
||||
toDistroboxConf = lib.generators.toKeyValue {
|
||||
listsAsDuplicateKeys = false;
|
||||
mkKeyValue = lib.generators.mkKeyValueDefault {
|
||||
@ -10,12 +13,13 @@ let
|
||||
if v == true then "1"
|
||||
else if v == false then "0"
|
||||
else if lib.isString v then ''"${v}"''
|
||||
else if lib.isList v then lib.concatStringsSep " " v
|
||||
else if lib.isPath v then lib.escapeShellArg v
|
||||
else if lib.isList v then ''"${lib.concatStringsSep " " v}"''
|
||||
else lib.generators.mkValueStringDefault { } v;
|
||||
} "=";
|
||||
};
|
||||
|
||||
distroboxConfFormat = { }: {
|
||||
distroboxConf = { }: {
|
||||
type = with lib.types;
|
||||
let
|
||||
valueType = oneOf [
|
||||
@ -32,20 +36,27 @@ let
|
||||
generate = name: value: pkgs.writeText name (toDistroboxConf value);
|
||||
};
|
||||
|
||||
settingsFormat = distroboxConfFormat { };
|
||||
settingsFormat = distroboxConf { };
|
||||
|
||||
settingsFile = settingsFormat.generate "distrobox-settings" cfg.settings;
|
||||
in
|
||||
{
|
||||
options.programs.distrobox = {
|
||||
enable = lib.mkEnableOption "Distrobox";
|
||||
|
||||
package = lib.mkPackageOption pkgs "distrobox" { };
|
||||
|
||||
settings = lib.mkOption {
|
||||
type = settingsFormat.type;
|
||||
default = { };
|
||||
description = ''
|
||||
Settings to be included for Distrobox.
|
||||
System-wide settings for Distrobox to be generated at
|
||||
{file}`/etc/distrobox/distrobox.conf`.
|
||||
|
||||
For more options, you could look at the list of variables and their
|
||||
default values from the source code of each Distrobox command [such as
|
||||
the ones from
|
||||
`distrobox-create`](https://github.com/89luca89/distrobox/blob/9309e1ebe5c70fd1f9b5286fd3a76f3e7bd995bd/distrobox-create#L48-L76).
|
||||
|
||||
::: {.note}
|
||||
You don't have surround the string values with double quotes since the
|
||||
@ -58,7 +69,9 @@ in
|
||||
"/nix/store:/nix/store:r"
|
||||
"/etc/profiles/per-user:/etc/profiles/per-user:r"
|
||||
];
|
||||
|
||||
container_image_default = "registry.opensuse.org/opensuse/distrobox-packaging:latest";
|
||||
container_command = "sh -norc";
|
||||
unshare_ipc = true;
|
||||
unshare_netns = true;
|
||||
}
|
||||
@ -88,6 +101,6 @@ in
|
||||
|
||||
environment.systemPackages = [ cfg.package ];
|
||||
|
||||
environment.etc."distrobox/distrobox.conf".source = settingsFile;
|
||||
environment.etc."distrobox/distrobox.conf".source = lib.mkIf (cfg.settings != { }) settingsFile;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user