mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
treewide: reformat nixfmt-rfc-style
Reformat repository using new nixfmt-rfc-style.
This commit is contained in:
parent
5df48c4255
commit
cba2f9ce95
1051 changed files with 37028 additions and 26594 deletions
|
|
@ -1,4 +1,10 @@
|
|||
{ config, lib, options, pkgs, ... }:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
options,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cfg = config.services.mpdscribble;
|
||||
|
|
@ -11,7 +17,8 @@ let
|
|||
"jamendo" = "http://postaudioscrobbler.jamendo.com";
|
||||
"listenbrainz" = "http://proxy.listenbrainz.org";
|
||||
};
|
||||
in {
|
||||
in
|
||||
{
|
||||
options.services.mpdscribble = {
|
||||
|
||||
enable = lib.mkEnableOption ''
|
||||
|
|
@ -45,10 +52,9 @@ in {
|
|||
};
|
||||
|
||||
host = lib.mkOption {
|
||||
default = (if mpdCfg.network.listenAddress != "any" then
|
||||
mpdCfg.network.listenAddress
|
||||
else
|
||||
"localhost");
|
||||
default = (
|
||||
if mpdCfg.network.listenAddress != "any" then mpdCfg.network.listenAddress else "localhost"
|
||||
);
|
||||
defaultText = lib.literalExpression ''
|
||||
if config.${mpdOpt.network.listenAddress} != "any"
|
||||
then config.${mpdOpt.network.listenAddress}
|
||||
|
|
@ -80,29 +86,31 @@ in {
|
|||
};
|
||||
|
||||
endpoints = lib.mkOption {
|
||||
type = let
|
||||
endpoint = { name, ... }: {
|
||||
options = {
|
||||
url = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = endpointUrls.${name} or "";
|
||||
description =
|
||||
"The url endpoint where the scrobble API is listening.";
|
||||
type =
|
||||
let
|
||||
endpoint =
|
||||
{ name, ... }:
|
||||
{
|
||||
options = {
|
||||
url = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = endpointUrls.${name} or "";
|
||||
description = "The url endpoint where the scrobble API is listening.";
|
||||
};
|
||||
username = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
Username for the scrobble service.
|
||||
'';
|
||||
};
|
||||
passwordFile = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
description = "File containing the password, either as MD5SUM or cleartext.";
|
||||
};
|
||||
};
|
||||
};
|
||||
username = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
Username for the scrobble service.
|
||||
'';
|
||||
};
|
||||
passwordFile = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
description =
|
||||
"File containing the password, either as MD5SUM or cleartext.";
|
||||
};
|
||||
};
|
||||
};
|
||||
in lib.types.attrsOf (lib.types.submodule endpoint);
|
||||
in
|
||||
lib.types.attrsOf (lib.types.submodule endpoint);
|
||||
default = { };
|
||||
example = {
|
||||
"last.fm" = {
|
||||
|
|
@ -112,9 +120,7 @@ in {
|
|||
};
|
||||
description = ''
|
||||
Endpoints to scrobble to.
|
||||
If the endpoint is one of "${
|
||||
lib.concatStringsSep ''", "'' (builtins.attrNames endpointUrls)
|
||||
}" the url is set automatically.
|
||||
If the endpoint is one of "${lib.concatStringsSep ''", "'' (builtins.attrNames endpointUrls)}" the url is set automatically.
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
@ -122,100 +128,102 @@ in {
|
|||
|
||||
config = lib.mkIf cfg.enable {
|
||||
assertions = [
|
||||
(lib.hm.assertions.assertPlatform "services.mpdscribble" pkgs
|
||||
lib.platforms.linux)
|
||||
(lib.hm.assertions.assertPlatform "services.mpdscribble" pkgs lib.platforms.linux)
|
||||
];
|
||||
systemd.user.services.mpdscribble = let
|
||||
localMpd = (cfg.host == "localhost" || cfg.host == "127.0.0.1");
|
||||
systemd.user.services.mpdscribble =
|
||||
let
|
||||
localMpd = (cfg.host == "localhost" || cfg.host == "127.0.0.1");
|
||||
|
||||
mkSection = secname: secCfg: ''
|
||||
[${secname}]
|
||||
url = ${secCfg.url}
|
||||
username = ${secCfg.username}
|
||||
password = {{${secname}_PASSWORD}}
|
||||
journal = /var/lib/mpdscribble/${secname}.journal
|
||||
'';
|
||||
|
||||
endpoints =
|
||||
lib.concatStringsSep "\n" (lib.mapAttrsToList mkSection cfg.endpoints);
|
||||
cfgTemplate = pkgs.writeText "mpdscribble.conf" ''
|
||||
## This file was automatically genenrated by home-manager and will be
|
||||
## overwritten. Do not edit. Edit your home-manager configuration instead.
|
||||
|
||||
## mpdscribble - an audioscrobbler for the Music Player Daemon.
|
||||
## http://mpd.wikia.com/wiki/Client:mpdscribble
|
||||
|
||||
# HTTP proxy URL.
|
||||
${lib.optionalString (cfg.proxy != null) "proxy = ${cfg.proxy}"}
|
||||
|
||||
# The location of the mpdscribble log file. The special value
|
||||
# "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 = -
|
||||
|
||||
# How verbose mpdscribble's logging should be. Default is 1.
|
||||
verbose = ${toString cfg.verbose}
|
||||
|
||||
# How often should mpdscribble save the journal file? [seconds]
|
||||
journal_interval = ${toString cfg.journalInterval}
|
||||
|
||||
# The host running MPD, possibly protected by a password
|
||||
# ([PASSWORD@]HOSTNAME).
|
||||
host = ${
|
||||
(lib.optionalString (cfg.passwordFile != null) "{{MPD_PASSWORD}}@")
|
||||
+ cfg.host
|
||||
}
|
||||
|
||||
# The port that the MPD listens on and mpdscribble should try to
|
||||
# connect to.
|
||||
port = ${toString cfg.port}
|
||||
|
||||
${endpoints}
|
||||
'';
|
||||
|
||||
configFile =
|
||||
"\${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/mpdscribble/mpdscribble.conf";
|
||||
|
||||
replaceSecret = secretFile: placeholder: targetFile:
|
||||
lib.optionalString (secretFile != null) ''
|
||||
${pkgs.replace-secret}/bin/replace-secret '${placeholder}' '${secretFile}' "${targetFile}"
|
||||
mkSection = secname: secCfg: ''
|
||||
[${secname}]
|
||||
url = ${secCfg.url}
|
||||
username = ${secCfg.username}
|
||||
password = {{${secname}_PASSWORD}}
|
||||
journal = /var/lib/mpdscribble/${secname}.journal
|
||||
'';
|
||||
|
||||
preStart = pkgs.writeShellApplication {
|
||||
name = "mpdscribble-pre-start";
|
||||
runtimeInputs = [ pkgs.replace-secret pkgs.coreutils ];
|
||||
text = ''
|
||||
endpoints = lib.concatStringsSep "\n" (lib.mapAttrsToList mkSection cfg.endpoints);
|
||||
cfgTemplate = pkgs.writeText "mpdscribble.conf" ''
|
||||
## This file was automatically genenrated by home-manager and will be
|
||||
## overwritten. Do not edit. Edit your home-manager configuration instead.
|
||||
|
||||
## mpdscribble - an audioscrobbler for the Music Player Daemon.
|
||||
## http://mpd.wikia.com/wiki/Client:mpdscribble
|
||||
|
||||
# HTTP proxy URL.
|
||||
${lib.optionalString (cfg.proxy != null) "proxy = ${cfg.proxy}"}
|
||||
|
||||
# The location of the mpdscribble log file. The special value
|
||||
# "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 = -
|
||||
|
||||
# How verbose mpdscribble's logging should be. Default is 1.
|
||||
verbose = ${toString cfg.verbose}
|
||||
|
||||
# How often should mpdscribble save the journal file? [seconds]
|
||||
journal_interval = ${toString cfg.journalInterval}
|
||||
|
||||
# The host running MPD, possibly protected by a password
|
||||
# ([PASSWORD@]HOSTNAME).
|
||||
host = ${(lib.optionalString (cfg.passwordFile != null) "{{MPD_PASSWORD}}@") + cfg.host}
|
||||
|
||||
# The port that the MPD listens on and mpdscribble should try to
|
||||
# connect to.
|
||||
port = ${toString cfg.port}
|
||||
|
||||
${endpoints}
|
||||
'';
|
||||
|
||||
configFile = "\${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/mpdscribble/mpdscribble.conf";
|
||||
|
||||
replaceSecret =
|
||||
secretFile: placeholder: targetFile:
|
||||
lib.optionalString (secretFile != null) ''
|
||||
${pkgs.replace-secret}/bin/replace-secret '${placeholder}' '${secretFile}' "${targetFile}"
|
||||
'';
|
||||
|
||||
preStart = pkgs.writeShellApplication {
|
||||
name = "mpdscribble-pre-start";
|
||||
runtimeInputs = [
|
||||
pkgs.replace-secret
|
||||
pkgs.coreutils
|
||||
];
|
||||
text = ''
|
||||
configFile="${configFile}"
|
||||
mkdir -p "$(dirname "$configFile")"
|
||||
cp --no-preserve=mode,ownership -f "${cfgTemplate}" "$configFile"
|
||||
${replaceSecret cfg.passwordFile "{{MPD_PASSWORD}}" "$configFile"}
|
||||
${lib.concatStringsSep "\n" (
|
||||
lib.mapAttrsToList (
|
||||
secname: cfg: replaceSecret cfg.passwordFile "{{${secname}_PASSWORD}}" "$configFile"
|
||||
) cfg.endpoints
|
||||
)}
|
||||
'';
|
||||
};
|
||||
|
||||
start = pkgs.writeShellScript "mpdscribble-start" ''
|
||||
configFile="${configFile}"
|
||||
mkdir -p "$(dirname "$configFile")"
|
||||
cp --no-preserve=mode,ownership -f "${cfgTemplate}" "$configFile"
|
||||
${replaceSecret cfg.passwordFile "{{MPD_PASSWORD}}" "$configFile"}
|
||||
${lib.concatStringsSep "\n" (lib.mapAttrsToList (secname: cfg:
|
||||
replaceSecret cfg.passwordFile "{{${secname}_PASSWORD}}"
|
||||
"$configFile") cfg.endpoints)}
|
||||
exec "${lib.getExe cfg.package}" --no-daemon --conf "$configFile"
|
||||
'';
|
||||
};
|
||||
|
||||
start = pkgs.writeShellScript "mpdscribble-start" ''
|
||||
configFile="${configFile}"
|
||||
exec "${lib.getExe cfg.package}" --no-daemon --conf "$configFile"
|
||||
'';
|
||||
|
||||
in {
|
||||
Unit = {
|
||||
Description = "mpdscribble mpd scrobble client";
|
||||
After = [ "network.target" ] ++ lib.optional localMpd "mpd.service";
|
||||
in
|
||||
{
|
||||
Unit = {
|
||||
Description = "mpdscribble mpd scrobble client";
|
||||
After = [ "network.target" ] ++ lib.optional localMpd "mpd.service";
|
||||
};
|
||||
Install.WantedBy = [ "default.target" ];
|
||||
Service = {
|
||||
StateDirectory = "mpdscribble";
|
||||
RuntimeDirectory = "mpdscribble";
|
||||
RuntimeDirectoryMode = "700";
|
||||
# TODO use LoadCredential= instead of running preStart with full privileges?
|
||||
ExecStartPre = "+${preStart}/bin/mpdscribble-pre-start";
|
||||
ExecStart = "${start}";
|
||||
};
|
||||
};
|
||||
Install.WantedBy = [ "default.target" ];
|
||||
Service = {
|
||||
StateDirectory = "mpdscribble";
|
||||
RuntimeDirectory = "mpdscribble";
|
||||
RuntimeDirectoryMode = "700";
|
||||
# TODO use LoadCredential= instead of running preStart with full privileges?
|
||||
ExecStartPre = "+${preStart}/bin/mpdscribble-pre-start";
|
||||
ExecStart = "${start}";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
meta.maintainers = [ lib.hm.maintainers.msyds ];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue