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: added navidrome module #92621

Closed
wants to merge 1 commit into from
Closed

nixos: added navidrome module #92621

wants to merge 1 commit into from

Conversation

aciceri
Copy link
Member

@aciceri aciceri commented Jul 7, 2020

I had to recreate this pull request since I deleted my fork, this was the old one: #91366
I'll continue the discussion here.

I hate to make suggestions and not follow through.

@aanderse don't worry, at the end with I solved generating a json instead of the a toml:

Navidrome also supports JSON and YML config files, if it makes it easier for you

@deluan thank you, now it writes a settings.json file in /etc/navidrome/settings.json

In conclusion the module options are:

  • navidrome.enable
  • navidrome.user and navidrome.group (defaults are navidrome both for user and group)
  • navidrome.musicFolderPermissions (default is 755)
  • navidrome.settings that is if type type.attrs and reflects the official navidrome settings. I chose to always overwrite with defaults value for DataFolder and ConfigFile.

I point out as it's impossible to build the derivation without navidrome.settings.MusicFolder and a error is thrown. I think this is ok as it wouldn't make any sense to execute navidrome without a music folder.

In my opinion it should me mergeable now, I hope the commit comment is ok, I don't want to try a new rebase...

nixos/modules/services/misc/navidrome.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/navidrome.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/navidrome.nix Outdated Show resolved Hide resolved
];

environment.etc."navidrome/settings.json".text = builtins.toJSON (cfg.settings // {
# These settings are always overwritten by NixOS i.e. they are not settable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better idea to set these settings would be using services.navidrome.settings itself.
I'm not sure but I think that it would also give an error in case a user tries to change settings.DataFolder directly, because the option is already defined in this module (it still can be done but requires lib.mkForce).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think to understand what you mean, could you provide an example on how you intend to edit the code?
I tried to explicitly set settings.DataFolder but it is correctly overwritten, moreover an user reading the documentation has no idea that such an option exists.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you provide an example on how you intend to edit the code?

Sure, I meant something like this:

{
  config = mkIf cfg.enable {

    environment.etc."navidrome/settings.json".text = 
      builtins.toJSON cfg.settings;

    services.navidrome.settings = {
      DataFolder = dataFolder;
      ConfigFile = configFile;
    } // optionalAttrs (hasAttrByPath ["Port"] cfg.settings) {
      Port = builtins.toString cfg.settings.Port;
    };

  };

}

moreover an user reading the documentation has no idea that such an option exists.

Well, to change navidrome.settings they are supposed to read the documentation you linked anyway, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, to change navidrome.settings they are supposed to read the documentation you linked anyway, no?

Oh. yes, you're right, I thought you meant the NixOS docs, not the navidrome one.

optionalAttrs (hasAttrByPath ["Port"] cfg.settings) {
      Port = builtins.toString cfg.settings.Port;
}

I cannot build this:

error: infinite recursion encountered, at /path/to/.../nixpkgs/lib/modules.nix:383:9
(use '--show-trace' to show detailed location information)

Any suggestion?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, that was pretty stupid: it's recursive. You could use the apply argument of mkOption to modify the settings after the evaluation but it seems it's not necessary to convert it to a string. I made a quick test with

import ./make-test-python.nix ({ pkgs, ... }: {
  name = "navidrome";

  machine = { ... }: {
    services.navidrome.enable = true;
    services.navidrome.settings = {
      MusicFolder = "/var/music";
      Port = 4535;
    };
  };

  testScript = ''
    machine.wait_for_unit("navidrome")
    machine.wait_for_open_port("4535")
  '';
})

and it works. You could add this to nixos/tests. Even if it's trivial is good to chek if the nixos module evaluates and there are no errors in the navidrome config file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I kept the module derivation as it was and I added your test. Is this ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should really drop the part about converting settings.Port: navidrome can handle numeric values just fine, there's no need to convert it to a string.

Also, a nice thing would be to add the test to the list in nixos/tests/all-test.nix list and link it to the package expression. Try something like this

--- a/pkgs/servers/misc/navidrome/default.nix
+++ b/pkgs/servers/misc/navidrome/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, ffmpeg, ffmpegSupport ? true, makeWrapper }:
+{ stdenv, fetchurl, ffmpeg, ffmpegSupport ? true, makeWrapper, nixosTests }:
 
 with stdenv.lib;
 
@@ -26,6 +26,8 @@ stdenv.mkDerivation rec {
     wrapProgram $out/bin/navidrome \
       --prefix PATH : ${makeBinPath (optional ffmpegSupport ffmpeg)}
   '';
+
+  passthru.tests.navidrome = nixosTests.navidrome;
   
   meta = {
     description = "Navidrome Music Server and Streamer compatible with Subsonic/Airsonic";

In this way @GrahamcOfBorg will run the test automatically next time you update the package.

Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple thoughts I had.

nixos/modules/services/misc/navidrome.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/navidrome.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/navidrome.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/navidrome.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/navidrome.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/navidrome.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/navidrome.nix Outdated Show resolved Hide resolved
Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more suggestions. Looking good though 👍

nixos/modules/services/misc/navidrome.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/navidrome.nix Outdated Show resolved Hide resolved
ConfigFile = configFile;
};

systemd.services.navidrome = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could potentially use the upstream systemd unit (https://github.com/deluan/navidrome/blob/master/contrib/navidrome.service) and override options as necessary by packaging it appropriately (moving to /lib/systemd/system directory) in the navidrome derivation.

enable = mkEnableOption "Navidrome music server and streamer";

settings = lib.mkOption {
type = with types; attrsOf (oneOf [ int str ]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to use the toml format from #75584

ND_CONFIGFILE = configFile;
};
serviceConfig = {
ExecStart = "${pkgs.navidrome}/bin/navidrome";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have the pkg configurable, to be able to use a version from unstable, for example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an overlay accomplishes this nicely.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

@stale
Copy link

stale bot commented Jul 21, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 21, 2021
@aciceri
Copy link
Member Author

aciceri commented Sep 13, 2021

Duplicate of #128201

@aciceri aciceri marked this as a duplicate of #128201 Sep 13, 2021
@aciceri aciceri closed this Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants