2024-05-05 18:08:28 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
tree,
|
|
|
|
...
|
|
|
|
}: let
|
2024-05-09 08:19:31 +01:00
|
|
|
alsaDevice = "sysdefault:CARD=A";
|
|
|
|
alsaControl = "Headphone";
|
|
|
|
mpvDevice = "alsa/${alsaDevice}";
|
|
|
|
hardwareVolume = 80;
|
2024-05-05 18:08:28 +01:00
|
|
|
|
|
|
|
startMusicPlayer = pkgs.writeShellScriptBin "startMusicPlayer" ''
|
2024-05-09 08:19:31 +01:00
|
|
|
${pkgs.alsa-utils}/bin/amixer -D "${alsaDevice}" sset "${alsaControl}" "${toString hardwareVolume}%"
|
|
|
|
|
2024-05-05 18:08:28 +01:00
|
|
|
exec ${pkgs.mpv}/bin/mpv \
|
|
|
|
"https://music:$(cat /secrets/music_stream_password)@mpd.owo.monster/flac" \
|
|
|
|
--cache=yes --cache-pause-initial=yes --cache-pause-wait=5 \
|
|
|
|
--vo=gpu --force-window --script-opts-append=osc-visibility=always \
|
2024-05-09 08:19:31 +01:00
|
|
|
--ao=alsa --audio-device="${mpvDevice}"
|
2024-05-05 18:08:28 +01:00
|
|
|
'';
|
2024-05-09 08:19:31 +01:00
|
|
|
|
2024-05-05 18:08:28 +01:00
|
|
|
startMusicPlayerSession = pkgs.writeShellScriptBin "startMusicPlayerSession" ''
|
|
|
|
set -x
|
|
|
|
export XDG_RUNTIME_DIR=/run/user/$UID
|
|
|
|
|
|
|
|
dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY XDG_CURRENT_DESKTOP
|
|
|
|
|
|
|
|
exec systemd-inhibit --what=sleep:idle:handle-lid-switch ${startMusicPlayer}/bin/startMusicPlayer
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
imports = with tree; [
|
|
|
|
profiles.connectivity.networkManager
|
|
|
|
profiles.wifiHardware
|
|
|
|
];
|
|
|
|
|
|
|
|
environment.systemPackages = [startMusicPlayer startMusicPlayerSession];
|
|
|
|
|
|
|
|
users.users.music-player = {
|
2024-05-09 08:19:31 +01:00
|
|
|
uid = 1001;
|
2024-05-05 18:08:28 +01:00
|
|
|
isNormalUser = true;
|
|
|
|
linger = true;
|
|
|
|
extraGroups = [
|
|
|
|
"video"
|
|
|
|
"input"
|
|
|
|
"audio"
|
|
|
|
"rtkit"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
home-manager.users.music-player = {
|
|
|
|
programs.mpv.enable = true;
|
|
|
|
imports = with tree; [
|
|
|
|
home.base
|
|
|
|
];
|
|
|
|
home.stateVersion = "23.05";
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services."music-player" = {
|
|
|
|
enable = true;
|
|
|
|
after = [
|
|
|
|
"systemd-user-sessions.service"
|
|
|
|
"plymouth-start.service"
|
|
|
|
"plymouth-quit.service"
|
|
|
|
"systemd-logind.service"
|
|
|
|
"getty@tty1.service"
|
2024-05-09 08:19:31 +01:00
|
|
|
"user@1001.service"
|
2024-05-05 18:08:28 +01:00
|
|
|
"network.target"
|
|
|
|
];
|
|
|
|
before = ["music-player.target"];
|
2024-05-09 08:19:31 +01:00
|
|
|
wants = ["dbus.socket" "network.target" "user@1001.service" "systemd-logind.service" "plymouth-quit.service"];
|
2024-05-05 18:08:28 +01:00
|
|
|
wantedBy = ["music-player.target"];
|
|
|
|
conflicts = ["getty@tty1.service"];
|
|
|
|
|
|
|
|
restartIfChanged = true;
|
|
|
|
unitConfig.ConditionPathExists = "/dev/tty1";
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.cage}/bin/cage -s ${startMusicPlayerSession}/bin/startMusicPlayerSession
|
|
|
|
'';
|
|
|
|
User = "music-player";
|
2024-05-09 08:19:31 +01:00
|
|
|
StandardError = "append:/var/log/music-player.log";
|
2024-05-05 18:08:28 +01:00
|
|
|
IgnoreSIGPIPE = "no";
|
|
|
|
UtmpIdentifier = "%n";
|
|
|
|
UtmpMode = "user";
|
|
|
|
TTYPath = "/dev/tty1";
|
|
|
|
TTYReset = "yes";
|
|
|
|
TTYVHangup = "yes";
|
|
|
|
TTYVTDisallocate = "yes";
|
|
|
|
StandardInput = "tty-fail";
|
|
|
|
PAMName = "music-player";
|
|
|
|
};
|
|
|
|
environment = {
|
|
|
|
XDG_RUNTIME_DIR = "/run/user/1001";
|
|
|
|
XDG_SESSION_TYPE = "wayland";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
security.polkit.enable = true;
|
|
|
|
|
|
|
|
security.pam.services.music-player.text = ''
|
|
|
|
auth required pam_unix.so nullok
|
|
|
|
account required pam_unix.so
|
|
|
|
session required pam_unix.so
|
|
|
|
session required pam_env.so conffile=/etc/pam/environment readenv=0
|
|
|
|
session required ${config.systemd.package}/lib/security/pam_systemd.so
|
|
|
|
'';
|
|
|
|
|
|
|
|
hardware.opengl.enable = true;
|
|
|
|
|
|
|
|
systemd.targets.music-player = {
|
|
|
|
description = "Music player";
|
2024-05-09 08:19:31 +01:00
|
|
|
wants = ["music-player.service" "networkmanager.service" "user@1001.service"];
|
2024-05-05 18:08:28 +01:00
|
|
|
};
|
|
|
|
}
|