1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00

feat(mpd-fm): open mpd port to local network, removing the need for a password

This commit is contained in:
2021-04-08 19:25:05 +02:00
parent ebbbb537c3
commit 69ed97a4ab
2 changed files with 22 additions and 3 deletions

View File

@@ -1,5 +1,7 @@
{ config, pkgs, lib, ... }:
let
firewall = (import <niveum/lib>).firewall lib;
streams = import <niveum/lib/streams.nix> {
di-fm-key = lib.strings.fileContents <secrets/di.fm/key>;
};
@@ -18,8 +20,6 @@ in
log_level "default"
auto_update "yes"
password "${password}@read,add,control"
audio_output {
type "pulse"
name "zaatar single room audio system"
@@ -41,6 +41,20 @@ in
environment.systemPackages = [ pkgs.mpc_cli ];
networking.firewall =
let
dport = config.services.mpd.network.port;
protocol = "tcp";
rules = [
(firewall.accept { inherit dport protocol; source = "192.168.0.0/16"; })
(firewall.accept { inherit dport protocol; source = "127.0.0.0/8"; })
];
in {
allowedTCPPorts = [ 80 ];
extraCommands = firewall.addRules rules;
extraStopCommands = firewall.removeRules rules;
};
system.activationScripts.mpd-playlists =
let playlistFile = pkgs.writeText "radio.m3u" (lib.concatMapStringsSep "\n" (lib.getAttr "stream") streams);
in ''
@@ -74,7 +88,6 @@ in
'';
};
networking.firewall.allowedTCPPorts = [ 80 config.services.mpd.network.port ];
services.nginx = {
enable = true;

View File

@@ -7,6 +7,12 @@ rec {
tmpfilesConfig = {type, path, mode ? "-", user ? "-", group ? "-", age ? "-", argument ? "-"}: "${type} '${path}' ${mode} ${user} ${group} ${age} ${argument}";
firewall = lib: {
accept = { source, protocol, dport }: "nixos-fw -s ${lib.escapeShellArg source} -p ${lib.escapeShellArg protocol} --dport ${lib.escapeShellArg (toString dport)} -j nixos-fw-accept";
addRules = lib.concatMapStringsSep "\n" (rule: "iptables -A ${rule}");
removeRules = lib.concatMapStringsSep "\n" (rule: "iptables -D ${rule} || true");
};
sshPort = 22022;
colours = import ./colours/mac-os.nix;