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/mpdscribble: init #97553

Merged
merged 1 commit into from Jan 10, 2021
Merged

nixos/mpdscribble: init #97553

merged 1 commit into from Jan 10, 2021

Conversation

Sohalt
Copy link
Contributor

@Sohalt Sohalt commented Sep 9, 2020

Motivation for this change

This adds a NixOS service for mpdscribble.

There have been prior attempts at this: #23660 #9940 #6806

Things done

I have the module running and working using a configuration of

services.mpdscribble = {
    enable = true;
    endpoints = {
      "libre.fm" = {
        username = "redacted";
        password = "redacted";
      };
      "last.fm" = {
        username = "redacted";
        password = "redacted";
      };
    };
  }

The password is stored either as MD5 or cleartext directly in the config file in the nix store. The description specifically states this.
It is not ideal, but ok for now IMHO. I've opened an issue upstream to support a password_file option (MusicPlayerDaemon/mpdscribble#24).

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@doronbehar
Copy link
Contributor

I like this. @matthiasbeyer do you have anything to comment?

I haven't deeply reviewed this PR yet. But, I'd like to verify that the passwords are handled right. As part of that, I'm waiting for a review at #95599 which I see as a dependency for this module's keeping passwords safe.

@doronbehar
Copy link
Contributor

For reference, I'm using mpdas which is a similar daemon, in my personal config for a while now, with both #95599 in my nixpkgs fork and this:

    systemd.services.mpdas = {
      description = "Music Player Daemon Scrobbler (mpdas)";
      bindsTo = ["mpd.service"];
      wantedBy = [ "multi-user.target" ];
      unitConfig = {
        RequiresMountsFor = "/var/lib/mpd";
      };
      # workaround for https://github.com/hrkfdn/mpdas/issues/58 
      environment.HOME = "/";
      serviceConfig = {
        User = "mpd";
        # That file's format is configured here:
        # https://github.com/hrkfdn/mpdas/tree/master#configuration
        ExecStart = "${pkgs.mpdas}/bin/mpdas -c /etc/mpdasrc";
        # A little bit more complicated then mpd's prestart script because it
        # has to parse the mpd conf file format
        ExecStartPre = pkgs.writeScript "mpdas-start-pre" ''
          #!${pkgs.runtimeShell}
          set -euo pipefail
          password=$(${pkgs.gawk}/bin/awk -F'[@"]' '$1 == "password " {print $2}' /var/lib/secrets/mpd.conf)
          echo "mpdpassword = $password" > /etc/mpdasrc
          cat /var/lib/secrets/mpdas.conf >> /etc/mpdasrc
        '';
        Type = "simple";
      };
    };
    environment.etc."mpdasrc" = {
      mode = "0660";
      group = "transmission";
      user = "mpd";
      text = ''
      '';
    };

Where /var/lib/secrets/mpdas.conf is where I keep my librefm password and username.


# The host running MPD, possibly protected by a password
# ([PASSWORD@]HOSTNAME).
host = ${cfg.host}
Copy link
Contributor

Choose a reason for hiding this comment

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

@Sohalt I was trying to suggest, that mpd's password shouldn't be plain visible here, and more over, at the store. You should use a environment.etc. file, with the proper permissions for the mpdscribble user. But, this is a dumb request when we do write to the store the mpd passwords - without #95599 . Could you give me a hand there with a review / test please?

@matthiasbeyer
Copy link
Contributor

I like this. @matthiasbeyer do you have anything to comment?

No, I don't use lastfm/etc anymore.

@Sohalt Sohalt force-pushed the nixos/mpdscribble branch 2 times, most recently from 3be68aa to cde9d33 Compare December 20, 2020 20:31
@doronbehar
Copy link
Contributor

@Sohalt I've only taken a rough look in the meantime and it looks fantastically promising :). I've failed in the attempt of doing it myself! Thanks so much for working on this. There's an ofborg eval error though: https://gist.github.com/GrahamcOfBorg/b3fb7048bc6528d554c2421e8353c812

@Sohalt
Copy link
Contributor Author

Sohalt commented Dec 23, 2020

@doronbehar Thanks! I've somehow missed that. Now everything's green :)

Copy link
Contributor

@doronbehar doronbehar left a comment

Choose a reason for hiding this comment

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

Other then that LGTM but I haven't tested.

nixos/modules/services/audio/mpdscribble.nix Outdated Show resolved Hide resolved
nixos/modules/services/audio/mpdscribble.nix Outdated Show resolved Hide resolved
nixos/modules/services/audio/mpdscribble.nix 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.

I think this module needs a few changes before it is ready. If you need any clarification, or even help, please don't hesitate to ping me and I'll do what I can. Thanks for working on this, it seems like a desired feature for our OS 👍

nixos/modules/services/audio/mpdscribble.nix Outdated Show resolved Hide resolved
nixos/modules/services/audio/mpdscribble.nix Outdated Show resolved Hide resolved
nixos/modules/services/audio/mpdscribble.nix Show resolved Hide resolved
nixos/modules/services/audio/mpdscribble.nix Show resolved Hide resolved
nixos/modules/services/audio/mpdscribble.nix Outdated Show resolved Hide resolved
nixos/modules/services/audio/mpdscribble.nix Outdated Show resolved Hide resolved
nixos/modules/services/audio/mpdscribble.nix Outdated Show resolved Hide resolved
nixos/modules/services/audio/mpdscribble.nix Outdated Show resolved Hide resolved
@Sohalt
Copy link
Contributor Author

Sohalt commented Dec 23, 2020

@aanderse @doronbehar thanks a lot for your review! I think I've addressed everything.

Copy link
Contributor

@doronbehar doronbehar left a comment

Choose a reason for hiding this comment

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

Built my system with this and without the typo and it seems fairly functional.

Endpoints to scrobble to.
If the endpoint is one of "${
concatStringsSep "\", \"" (attrNames endpointUrls)
}" the url is set automatically.
Copy link
Contributor

Choose a reason for hiding this comment

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

Saying the url is set automatically gives a slight feeling it's possible to set a certain url, for an arbitrary endpoint, but there isn't.. So maybe remove that last part of the sentence? Or alternatively provide a default value for a url option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I understand you correctly. You can set an arbitrary url for an arbitrary endpoint, but when you use one of the predefined endpoints, there is already a default with the "official" endpoint for those services (defined here).

# "syslog" makes mpdscribble use the local syslog daemon. On most
# systems, log messages will appear in /var/log/daemon.log then.
# "-" means log to stderr (the current terminal).
log = -
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we remove this option? I personally like the idea of having the list of scrobbles also in a separate file. If I remember correctly that this is what this log holds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does not only hold lists of scrobbles but also other logging output. There is the journal, which is used to store a list of scrobbles when there is no connection to the scrobble server.
Since the service runs as DynamicUser it does not make too much sense to be able to specify a separate location, because the service won't have access (I could add ReadWritePaths, but I don't think it's really necessary. - will make mpdscribble log to the systemd journal.

nixos/modules/services/audio/mpdscribble.nix Outdated Show resolved Hide resolved
@Sohalt Sohalt force-pushed the nixos/mpdscribble branch 2 times, most recently from efd7afc to bcb6e3a Compare December 25, 2020 20:52
@Sohalt Sohalt marked this pull request as draft December 26, 2020 17:22
@Sohalt
Copy link
Contributor Author

Sohalt commented Dec 26, 2020

I have a commit that automatically sets the passwordFile to the correct value if it is configured through the services.mpd.credentials option that I've added here #107508
I think it would make sense to merge that first, then I can add that commit and this PR will already include that useful feature.

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.

LGTM 👍

@doronbehar
Copy link
Contributor

doronbehar commented Jan 4, 2021 via email

@doronbehar
Copy link
Contributor

From some reason I wasn't able to merge this on top of #107508 so I didn't test this. So let's unmark it as a draft and rebase?

@Sohalt Sohalt marked this pull request as ready for review January 9, 2021 22:38
Copy link
Contributor

@doronbehar doronbehar left a comment

Choose a reason for hiding this comment

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

Works! Thanks so much for working on this. Enjoy the music 🎷.

@doronbehar doronbehar merged commit 054b7c4 into NixOS:master Jan 10, 2021
@Sohalt
Copy link
Contributor Author

Sohalt commented Jan 10, 2021

Thank you for the review and merging!

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

4 participants