forked from Yuka/c3h-nixfiles
Compare commits
7 commits
fix_spotif
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
dd18c6753a | ||
|
f868637417 | ||
|
c5349029ab | ||
d1ebaa7a86 | |||
956e105dfb | |||
c698432f2f | |||
dbfb1dfc17 |
7 changed files with 116 additions and 20 deletions
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Leitstelle config management
|
||||||
|
|
||||||
|
To deploy, run `./deploy.sh switch <host>`, where the host is nuc or bemmer.
|
|
@ -38,6 +38,7 @@
|
||||||
vim
|
vim
|
||||||
wget
|
wget
|
||||||
jq
|
jq
|
||||||
|
lsof
|
||||||
];
|
];
|
||||||
|
|
||||||
programs.bash.shellAliases = {
|
programs.bash.shellAliases = {
|
||||||
|
|
13
deploy.sh
13
deploy.sh
|
@ -6,7 +6,7 @@ cd "$(dirname "$0")"
|
||||||
if ! command -v nix-build &> /dev/null
|
if ! command -v nix-build &> /dev/null
|
||||||
then
|
then
|
||||||
echo "Nix installation could not be found. Please follow the instructions linked below."
|
echo "Nix installation could not be found. Please follow the instructions linked below."
|
||||||
echo "https://nixos.org/manual/nix/unstable/installation/installing-binary.html#multi-user-installation"
|
echo "https://nixos.org/manual/nix/unstable/installation/installing-binary.html"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -24,13 +24,12 @@ fi
|
||||||
echo "deploying $host to $target"
|
echo "deploying $host to $target"
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
tmp=$(mktemp -d)
|
|
||||||
trap 'rm -rf "$tmp"' EXIT
|
|
||||||
sources="$tmp/sources"
|
|
||||||
cp -r $(nix-build nix/sources-dir.nix --no-out-link) $tmp/sources
|
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
system_drv=$(nix-instantiate "<nixpkgs/nixos>" -A config.system.build.toplevel -I $sources -I "nixos-config=$PWD/hosts/$host/configuration.nix")
|
system_drv=$(
|
||||||
|
nix-instantiate "<nixpkgs/nixos>" -A config.system.build.toplevel \
|
||||||
|
-I "$(nix-build nix/sources-dir.nix --no-out-link)" \
|
||||||
|
-I "nixos-config=$PWD/hosts/$host/configuration.nix"
|
||||||
|
)
|
||||||
nix-copy-closure --to $target $system_drv
|
nix-copy-closure --to $target $system_drv
|
||||||
system=$(ssh $target "nix-store --realise $system_drv")
|
system=$(ssh $target "nix-store --realise $system_drv")
|
||||||
ssh $target "sudo nix-env -p /nix/var/nix/profiles/system -i $system && sudo /nix/var/nix/profiles/system/bin/switch-to-configuration $mode"
|
ssh $target "sudo nix-env -p /nix/var/nix/profiles/system -i $system && sudo /nix/var/nix/profiles/system/bin/switch-to-configuration $mode"
|
||||||
|
|
68
modules/spotifyd.nix
Normal file
68
modules/spotifyd.nix
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.services.spotifyd;
|
||||||
|
toml = pkgs.formats.toml {};
|
||||||
|
warnConfig =
|
||||||
|
if cfg.config != ""
|
||||||
|
then lib.trace "Using the stringly typed .config attribute is discouraged. Use the TOML typed .settings attribute instead."
|
||||||
|
else id;
|
||||||
|
spotifydConf =
|
||||||
|
if cfg.settings != {}
|
||||||
|
then toml.generate "spotify.conf" cfg.settings
|
||||||
|
else warnConfig (pkgs.writeText "spotifyd.conf" cfg.config);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
services.spotifyd = {
|
||||||
|
enable = mkEnableOption "spotifyd, a Spotify playing daemon";
|
||||||
|
|
||||||
|
config = mkOption {
|
||||||
|
default = "";
|
||||||
|
type = types.lines;
|
||||||
|
description = ''
|
||||||
|
(Deprecated) Configuration for Spotifyd. For syntax and directives, see
|
||||||
|
<link xlink:href="https://github.com/Spotifyd/spotifyd#Configuration"/>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
settings = mkOption {
|
||||||
|
default = {};
|
||||||
|
type = toml.type;
|
||||||
|
example = { global.bitrate = 320; };
|
||||||
|
description = ''
|
||||||
|
Configuration for Spotifyd. For syntax and directives, see
|
||||||
|
<link xlink:href="https://github.com/Spotifyd/spotifyd#Configuration"/>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = cfg.config == "" || cfg.settings == {};
|
||||||
|
message = "At most one of the .config attribute and the .settings attribute may be set";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
systemd.services.spotifyd = {
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
after = [ "network-online.target" "sound.target" ];
|
||||||
|
description = "spotifyd, a Spotify playing daemon";
|
||||||
|
environment.SHELL = "/bin/sh";
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStart = "${pkgs.spotifyd}/bin/spotifyd --no-daemon --config-path ${spotifydConf}";
|
||||||
|
Restart = "always";
|
||||||
|
RestartSec = 12;
|
||||||
|
DynamicUser = true;
|
||||||
|
CacheDirectory = "spotifyd";
|
||||||
|
SupplementaryGroups = ["audio"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
meta.maintainers = [ maintainers.anderslundstedt ];
|
||||||
|
}
|
|
@ -9,6 +9,6 @@ in
|
||||||
lib.concatStringsSep "\n" ([
|
lib.concatStringsSep "\n" ([
|
||||||
"mkdir $out"
|
"mkdir $out"
|
||||||
]
|
]
|
||||||
++ lib.mapAttrsToList (name: source: "ln -s ${source.outPath} $out/${name}") sources
|
++ lib.mapAttrsToList (name: source: "cp -r --reflink=auto ${source.outPath} $out/${name}") sources
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
"homepage": "https://github.com/nmattia/niv",
|
"homepage": "https://github.com/nmattia/niv",
|
||||||
"owner": "nmattia",
|
"owner": "nmattia",
|
||||||
"repo": "niv",
|
"repo": "niv",
|
||||||
"rev": "e0ca65c81a2d7a4d82a189f1e23a48d59ad42070",
|
"rev": "5830a4dd348d77e39a0f3c4c762ff2663b602d4c",
|
||||||
"sha256": "1pq9nh1d8nn3xvbdny8fafzw87mj7gsmp6pxkdl65w2g18rmcmzx",
|
"sha256": "1d3lsrqvci4qz2hwjrcnd8h5vfkg8aypq3sjd4g3izbc8frwz5sm",
|
||||||
"type": "tarball",
|
"type": "tarball",
|
||||||
"url": "https://github.com/nmattia/niv/archive/e0ca65c81a2d7a4d82a189f1e23a48d59ad42070.tar.gz",
|
"url": "https://github.com/nmattia/niv/archive/5830a4dd348d77e39a0f3c4c762ff2663b602d4c.tar.gz",
|
||||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||||
},
|
},
|
||||||
"nixos-hardware": {
|
"nixos-hardware": {
|
||||||
|
@ -17,10 +17,10 @@
|
||||||
"homepage": "",
|
"homepage": "",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixos-hardware",
|
"repo": "nixos-hardware",
|
||||||
"rev": "3aabf78bfcae62f5f99474f2ebbbe418f1c6e54f",
|
"rev": "2a7063461c3751d83869a2a0a8ebc59e34bec5b2",
|
||||||
"sha256": "10g240brgjz7qi20adwajxwqrqb5zxc79ii1mc20fasgqlf2a8sx",
|
"sha256": "173ms858wni43l2p7vqjarm2bnjdhpii0zgn46750nyfff1f2184",
|
||||||
"type": "tarball",
|
"type": "tarball",
|
||||||
"url": "https://github.com/NixOS/nixos-hardware/archive/3aabf78bfcae62f5f99474f2ebbbe418f1c6e54f.tar.gz",
|
"url": "https://github.com/NixOS/nixos-hardware/archive/2a7063461c3751d83869a2a0a8ebc59e34bec5b2.tar.gz",
|
||||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
|
@ -29,10 +29,10 @@
|
||||||
"homepage": "",
|
"homepage": "",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "34ad3ffe08adfca17fcb4e4a47bb5f3b113687be",
|
"rev": "581d2d6c9cd5c289002203581d8aa0861963a933",
|
||||||
"sha256": "02li241rz5668nfyp88zfjilxf0mr9yansa93fbl38hjwkhf3ix6",
|
"sha256": "1qpmqj075pppa6ihmkacf491lhq7rpxlcm8cm6h18raardsr3irr",
|
||||||
"type": "tarball",
|
"type": "tarball",
|
||||||
"url": "https://github.com/NixOS/nixpkgs/archive/34ad3ffe08adfca17fcb4e4a47bb5f3b113687be.tar.gz",
|
"url": "https://github.com/NixOS/nixpkgs/archive/581d2d6c9cd5c289002203581d8aa0861963a933.tar.gz",
|
||||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,36 @@
|
||||||
{ config, ... }:
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
|
disabledModules = [ "services/audio/spotifyd.nix" ];
|
||||||
|
imports = [ ../modules/spotifyd.nix ];
|
||||||
|
|
||||||
|
|
||||||
services.spotifyd = {
|
services.spotifyd = {
|
||||||
enable = true;
|
enable = true;
|
||||||
settings.zeroconf_port = 18572;
|
settings.global = {
|
||||||
|
bitrate = 320;
|
||||||
|
zeroconf_port = 18572;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.firewall.allowedTCPPorts = [ 4070 config.services.spotifyd.settings.zeroconf_port ];
|
networking.firewall.allowedTCPPorts = [ 4070 config.services.spotifyd.settings.global.zeroconf_port ];
|
||||||
networking.firewall.allowedUDPPorts = [ 5353 ];
|
networking.firewall.allowedUDPPorts = [ 5353 ];
|
||||||
|
|
||||||
|
systemd.services.restart-spotifyd = {
|
||||||
|
serviceConfig.Type = "oneshot";
|
||||||
|
script = ''
|
||||||
|
${pkgs.systemd}/bin/systemctl restart spotifyd.service
|
||||||
|
${pkgs.systemd}/bin/systemctl restart pulseaudio.service
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.timers.restart-spotifyd = {
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
partOf = [ "restart-spotifyd.service" ];
|
||||||
|
timerConfig = {
|
||||||
|
OnCalendar = "*-*-* 07:00:00";
|
||||||
|
Persistent = "True";
|
||||||
|
Unit = "restart-spotifyd.service";
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue