From 9dc093e32078008871e2c50a018f86de237ddc50 Mon Sep 17 00:00:00 2001 From: ChaotiCryptidz Date: Sun, 23 Jan 2022 11:48:43 +0000 Subject: [PATCH] add mpd and mpd sync --- hosts/lappy/lappy.nix | 3 +++ hosts/lappy/profiles/mpd-music-sync.nix | 21 ++++++++++++++++ hosts/lappy/profiles/mpd.nix | 32 +++++++++++++++++++++++++ outputs.nix | 2 ++ 4 files changed, 58 insertions(+) create mode 100644 hosts/lappy/profiles/mpd-music-sync.nix create mode 100644 hosts/lappy/profiles/mpd.nix diff --git a/hosts/lappy/lappy.nix b/hosts/lappy/lappy.nix index 9b8ddb7..41ed85e 100644 --- a/hosts/lappy/lappy.nix +++ b/hosts/lappy/lappy.nix @@ -28,6 +28,9 @@ # for sci-hub and whenever websites break profiles.tor + # Music! + hosts.lappy.profiles.mpd + # For cross compiling and deploying to raspberry profiles.cross.arm64 ]; diff --git a/hosts/lappy/profiles/mpd-music-sync.nix b/hosts/lappy/profiles/mpd-music-sync.nix new file mode 100644 index 0000000..f4b6f89 --- /dev/null +++ b/hosts/lappy/profiles/mpd-music-sync.nix @@ -0,0 +1,21 @@ +{ pkgs, ... }: let + passwordFile = "/secrets/mpd-music-sync-password"; +in { + systemd.tmpfiles.rules = [ "d /music 0755 mpd users -" ]; + systemd.services.mpd-music-sync = { + startAt = "daily"; + requires = [ "network.target" ]; + after = [ "network.target" ]; + path = [ pkgs.rclone ]; + script = '' + set -x + export PASSWORD=$(cat ${passwordFile}) + rclone sync :ftp:/storage/music /music \ + --ftp-host=hetzner-vm.servers.owo.monster \ + --ftp-port=4220 \ + --ftp-user=ftp-user \ + --ftp-pass=$(rclone obscure $PASSWORD) + chown mpd:users -R /music + ''; + }; +} diff --git a/hosts/lappy/profiles/mpd.nix b/hosts/lappy/profiles/mpd.nix new file mode 100644 index 0000000..596e861 --- /dev/null +++ b/hosts/lappy/profiles/mpd.nix @@ -0,0 +1,32 @@ +{ pkgs, tree, ... }: { + imports = [ ./mpd-music-sync.nix ]; + + hardware.pulseaudio = { + extraConfig = + "load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1"; + }; + + environment.systemPackages = with pkgs; [ mpc_cli ]; + + systemd.tmpfiles.rules = [ + "d /var/lib/mpd 0755 mpd mpd -" + "d /var/lib/mpd/data 0755 mpd mpd -" + "d /var/lib/mpd/playlists 0755 mpd mpd -" ]; + + services.mpd = { + enable = true; + dataDir = "/var/lib/mpd/data"; + playlistDirectory = "/var/lib/mpd/playlists"; + musicDirectory = "/music"; + extraConfig = '' + host_permissions "127.0.0.1 read,add,control,admin" + audio_output { + type "pulse" + name "Pulseaudio" + server "127.0.0.1" + } + ''; + }; + + systemd.services.mpd.serviceConfig.StateDirectory = [ "/music" "/var/lib/mpd" ]; +} diff --git a/outputs.nix b/outputs.nix index 890d52f..9d49835 100644 --- a/outputs.nix +++ b/outputs.nix @@ -6,6 +6,8 @@ let folder = ./.; config = { "hosts/*/services".functor.enable = true; + "hosts/*/home".functor.enable = true; + "hosts/*/profiles".functor.enable = true; "profiles/*".functor.enable = true; "profiles/sound/*".functor.enable = true; "profiles/connectivity/*".functor.enable = true;