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

nixos/minidlna: add options for user and group #373604

Closed
wants to merge 1 commit into from
Closed
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
nixos/minidlna: add options for user and group
This adds configuration options to specify the user/group to use for
running the MiniDLNA daemon.

The default `minidlna` user/group will not be created when a different
user/group is specified.

Co-authored-by: Arne Keller <2012gdwu+github@posteo.de>
  • Loading branch information
earldouglas and FliegendeWurst committed Dec 15, 2024
commit 144f1edb62d428212afb6cb8fbd5b43e50b43e83
37 changes: 29 additions & 8 deletions nixos/modules/services/networking/minidlna.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ let
cfg = config.services.minidlna;
settingsFormat = pkgs.formats.keyValue { listsAsDuplicateKeys = true; };
settingsFile = settingsFormat.generate "minidlna.conf" cfg.settings;
defaultUser = "minidlna";
defaultGroup = defaultUser;
in

{
Expand Down Expand Up @@ -107,6 +109,20 @@ in
};
};

options.services.minidlna.user = mkOption {
type = types.str;
default = defaultUser;
example = "yourUser";
description = "Overrides the default user used to run MiniDLNA. Skips the creation of the default `${defaultUser}` user.";
};

options.services.minidlna.group = mkOption {
type = types.str;
default = defaultGroup;
example = "yourGroup";
description = "Overrides the default group used to run MiniDLNA. Skips the creation of the default `${defaultGroup}` group.";
};

imports = [
(mkRemovedOptionModule [ "services" "minidlna" "config" ] "")
(mkRemovedOptionModule [ "services" "minidlna" "extraConfig" ] "")
Expand All @@ -122,22 +138,27 @@ in
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.settings.port ];
networking.firewall.allowedUDPPorts = mkIf cfg.openFirewall [ 1900 ];

users.users.minidlna = {
description = "MiniDLNA daemon user";
group = "minidlna";
uid = config.ids.uids.minidlna;
};
users.users = mkIf (cfg.user == defaultUser) {
${defaultUser} =
{ group = cfg.group;
uid = config.ids.uids.minidlna;
description = "MiniDLNA daemon user";
};
};

users.groups.minidlna.gid = config.ids.gids.minidlna;
users.groups = mkIf (cfg.group == defaultGroup) {
${defaultGroup}.gid =
config.ids.gids.minidlna;
};

systemd.services.minidlna = {
description = "MiniDLNA Server";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];

serviceConfig = {
User = "minidlna";
Group = "minidlna";
User = cfg.user;
Group = cfg.group;
CacheDirectory = "minidlna";
RuntimeDirectory = "minidlna";
PIDFile = "/run/minidlna/pid";
Expand Down
Loading