How to setup a simple DLNA server in NixOS?

My system:

  • NixOS (unstable)
  • home-manager (master, standalone, flakes)

I am trying to setup a simple DLNA server.

Nothing like UMS or Plex.

I am thinking of much simpler options like miniDLNA or dms or rygel.

Lucky miniDLNA is available in nixpkgs.

I saw the options for miniDLNA and setup my home-manager as such:

~/.config/home-manager home.nix
  # DLNA Server
  services.minidlna.settings.enable = true;
  services.minidlna.settings.notify_interval = 60;
  services.minidlna.settings.friendly_name = "PCMEDIA";
  services.minidlna.settings.media_dir = ["V,/mnt/ORION/DLNA/"];  
{ config, pkgs, ... }:

{
  # Home Manager needs a bit of information about you and the paths it should
  # manage.
  home.username = "moss";
  home.homeDirectory = "/home/moss";

  # This value determines the Home Manager release that your configuration is
  # compatible with. This helps avoid breakage when a new Home Manager release
  # introduces backwards incompatible changes.
  #
  # You should not change this value, even if you update Home Manager. If you do
  # want to update the value, then make sure to first check the Home Manager
  # release notes.
  home.stateVersion = "22.11"; # Please read the comment before changing.
  
  # The home.packages option allows you to install Nix packages into your
  # environment.
  home.packages = [
    # polybar dependencies
    pkgs.weather-icons
    pkgs.jq

    # pdf tools
    pkgs.poppler_utils

    # tor
    pkgs.tor-browser-bundle-bin
   
    # file download app
    pkgs.aria2
    
    # torrent client
    pkgs.qbittorrent
    
    # google chrome
    pkgs.google-chrome
    
    # ebook management
    pkgs.calibre

    # calculator
    pkgs.speedcrunch
    
    # chat
    pkgs.telegram-desktop

    # storage encryption
    pkgs.veracrypt

    # video download
    pkgs.yt-dlp

    # # It is sometimes useful to fine-tune packages, for example, by applying
    # # overrides. You can do that directly here, just don't forget the
    # # parentheses. Maybe you want to install Nerd Fonts with a limited number of
    # # fonts?
    # (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; })

    # # You can also create simple shell scripts directly inside your
    # # configuration. For example, this adds a command 'my-hello' to your
    # # environment:
    # (pkgs.writeShellScriptBin "my-hello" ''
    #   echo "Hello, ${config.home.username}!"
    # '')
  ];

# kitty Terminal

  programs.kitty = {
    enable = true;
    theme = "Github";
    font = {
      name = "JetBrainsMono Nerd Font Mono";
      size = 12;
    };
    settings = {
      #CURSOR
      cursor_shape = "beam";
      cursor_blink_interval = 1;
  
      #MOUSE
      copy_on_select = "yes";
  
      #Performance tuning
      repaint_delay = 0;
      input_delay = 0;
      sync_to_monitor = "no";

      #Window layout
      window_padding_width = "2 5";

      #Tab bar
      separator = "top";
      tab_bar_style = "separator";    
    };
  };

  # DLNA Server
  services.minidlna.settings.enable = true;
  services.minidlna.settings.notify_interval = 60;
  services.minidlna.settings.friendly_name = "PCMEDIA";
  services.minidlna.settings.media_dir = ["V,/mnt/ORION/DLNA/"];  

  # Home Manager is pretty good at managing dotfiles. The primary way to manage
  # plain files is through 'home.file'.
  home.file = {
    # # Building this configuration will create a copy of 'dotfiles/screenrc' in
    # # the Nix store. Activating the configuration will then make '~/.screenrc' a
    # # symlink to the Nix store copy.
    # ".screenrc".source = dotfiles/screenrc;

    # # You can also set the file content immediately.
    # ".gradle/gradle.properties".text = ''
    #   org.gradle.console=verbose
    #   org.gradle.daemon.idletimeout=3600000
    # '';
  };

  # You can also manage environment variables but you will have to manually
  # source
  #
  #  ~/.nix-profile/etc/profile.d/hm-session-vars.sh
  #
  # or
  #
  #  /etc/profiles/per-user/moss/etc/profile.d/hm-session-vars.sh
  #
  # if you don't want to manage your shell through Home Manager.
  home.sessionVariables = {
    EDITOR = "hx";
    TERMINAL = "kitty";
  };


  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;
}

But the switch fails:

$ home-manager switch
error: The option `services.minidlna' does not exist. Definition values:
       - In `/nix/store/rpwbpw76a21rgw7crvcmkp35vmxnq9xh-source/home.nix':
           {
             settings = {
               enable = true;
               friendly_name = "PCMEDIA";
               media_dir = [
           ...
(use '--show-trace' to show detailed location information)

It says “The option `services.minidlna’ does not exist.”


How can I setup miniDLNA?

services.minidlna only exists in nixos.

So I can’t use home-manager to configure it… Is there another way? Or should I just go with /etc/nixos/configuration.nix?

I have started using NixOS only a few days ago so I am n00b.

Yes, the minidlna module only exists in nixos, not home-manager.

As @Sandro has stated minidlna service doesn’t exist in home-manager right now. One needs to use /etc/nixos/configuration.nix.

The relevant configuration.nix snippet to setup minidlna in NixOS:

#DLNA
services.minidlna.enable = true;
services.minidlna.settings = {
  friendly_name = "DLNA MEDIA";
  media_dir = [
     "V,/mnt/media/Movies/" #Videos files are located here
     "A,/mnt/media/Songs/" #Audio files are here
 ];
  log_level = "error";
};

users.users.minidlna = {
  extraGroups = [ "users" ]; # so minidlna can access the files.
};
  • Make sure minidlna can access the media directories specified by adding the minidlna to the usergroup users.

  • If minidlna is listing the wrong files clear out the db_dir or /var/cache/minidlna/*.

1 Like

Also,

  # so changes in media dirs are updates in the server listing
  # also make sure "inotify-tools" packages is installed
  inotify = "yes"; 

Cheers, worked

{ config, pkgs, ... }:

{
  # DLNA service: Check if working. Open browser: http://192.168.0.13:8200/
  # Add: ports 8200
  # ------------------------------------------------------------------------
  services.minidlna.enable = true;
  services.minidlna.settings = {
    friendly_name = "NixOS-DLNA";

    #     https://mylinuxramblings.wordpress.com/2016/02/19/mini-how-to-installing-minidlna-in-ubuntu/
    #    "A" for audio    (eg. media_dir=A,/var/lib/minidlna/music)
    #    "P" for pictures (eg. media_dir=P,/var/lib/minidlna/pictures)
    #    "V" for video    (eg. media_dir=V,/var/lib/minidlna/videos)
    #    "PV" for pictures and video (eg. media_dir=PV,/var/lib/minidlna/digital_camera)

    media_dir = [
      "PV,/home/tolga/public/Music/" # Music files are located here
      "PV,/home/tolga/public/Vids/" # Audio files are here
      "PV,/mnt/sambashare/DLNA/"
      #"PV,/mnt/DLNA/"
    ];
 
    inotify = "yes";
    log_level = "error";
    announceInterval = 05;
  };

  users.users.minidlna = {
    extraGroups =
      [ "users" "samba" "wheel" "tolga" ]; # so minidlna can access the files.
  };

  networking.firewall = {
    enable = false;
    allowedTCPPorts = [ 8200 ];
    allowedUDPPorts = [ 8200 ];
  };

}

1 Like

ok, require help

DLNA works great on nixos, w11 picks it up and so does my andriod, but… my smart TV dosnt.

Smart TV, panasonic (old) picks up all except, nixos

Is it a firewall port # issuse?

networking.firewall.allowedTCPPorts = [ 139 445 8096 ];
networking.firewall.allowedUDPPorts = [ 137 138 1900 ];

Any help be appreciated

cheers

@tolgaerok, you may need services.avahi.enable = true; for the TV to find the DLNA server.

The rest of my minidlna config is simply

{
  services.minidlna = {
    enable = true;
    openFirewall = true;
    settings = {
      inotify = "yes";
      media_dir = [
        "V,/Video"
      ];
    };
  };
}

I do not specify any firewall rules; I think the minidlna module handles that.

If you suspect a firewall problem, disable it to test: networking.firewall.enable = false;.

thankyou for the reply, TV is still unable to see nixos miniDLNA