This commit is contained in:
parent
7dcbc66e80
commit
0696a90d23
|
@ -5,8 +5,80 @@
|
||||||
}:
|
}:
|
||||||
with lib; let
|
with lib; let
|
||||||
cfg = config.services.declarative-jellyfin;
|
cfg = config.services.declarative-jellyfin;
|
||||||
|
isStrList = x: builtins.all (x: builtins.isString x) x;
|
||||||
|
prepass = x:
|
||||||
|
if (builtins.isAttrs x)
|
||||||
|
then
|
||||||
|
if !(builtins.hasAttr "tag" x)
|
||||||
|
then
|
||||||
|
attrsets.mapAttrsToList
|
||||||
|
(tag: value: {
|
||||||
|
inherit tag;
|
||||||
|
content = prepass value;
|
||||||
|
})
|
||||||
|
x
|
||||||
|
else if (builtins.hasAttr "content" x)
|
||||||
|
then {
|
||||||
|
tag = x.tag;
|
||||||
|
content = prepass x.content;
|
||||||
|
}
|
||||||
|
else x
|
||||||
|
else if (builtins.isList x)
|
||||||
|
then
|
||||||
|
if (isStrList x)
|
||||||
|
then
|
||||||
|
(builtins.map
|
||||||
|
(content: {
|
||||||
|
tag = "string";
|
||||||
|
inherit content;
|
||||||
|
})
|
||||||
|
x)
|
||||||
|
else builtins.map prepass x
|
||||||
|
else x;
|
||||||
|
|
||||||
|
toXml = tag: x: (toXml' {
|
||||||
|
inherit tag;
|
||||||
|
attrib = {
|
||||||
|
"xmlns:xsi" = "http://www.w3.org/2001/XMLSchema-instance";
|
||||||
|
"xmlns:xsd" = "http://www.w3.org/2001/XMLSchema";
|
||||||
|
};
|
||||||
|
content = prepass x;
|
||||||
|
});
|
||||||
in {
|
in {
|
||||||
config = mkIf cfg.enable {
|
config =
|
||||||
# TODO: implement
|
mkIf cfg.enable
|
||||||
};
|
{
|
||||||
|
system.activationScripts = {
|
||||||
|
link-config-xml =
|
||||||
|
lib.stringAfter ["var"]
|
||||||
|
(
|
||||||
|
let
|
||||||
|
commands =
|
||||||
|
builtins.concatStringsSep "\n"
|
||||||
|
(builtins.map
|
||||||
|
(x: "cp -s \"${pkgs.writeText x.file (toXml x.name x.content)}\" \"/var/lib/jellyfin/config/${x.file}\"")
|
||||||
|
[
|
||||||
|
{
|
||||||
|
name = "NetworkConfiguration";
|
||||||
|
file = "network.xml";
|
||||||
|
content = cfg.network;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "EncodingOptions";
|
||||||
|
file = "encoding.xml";
|
||||||
|
content = cfg.encoding;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "ServerConfiguration";
|
||||||
|
file = "system.xml";
|
||||||
|
content = cfg.system;
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
in ''
|
||||||
|
mkdir -p "/var/lib/jellyfin/config"
|
||||||
|
${commands}
|
||||||
|
''
|
||||||
|
);
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,83 +17,4 @@ in
|
||||||
options.services.declarative-jellyfin = {
|
options.services.declarative-jellyfin = {
|
||||||
enable = mkEnableOption "Jellyfin Service";
|
enable = mkEnableOption "Jellyfin Service";
|
||||||
};
|
};
|
||||||
|
|
||||||
config =
|
|
||||||
mkIf cfg.enable
|
|
||||||
(
|
|
||||||
let
|
|
||||||
isStrList = x: builtins.all (x: builtins.isString x) x;
|
|
||||||
prepass = x:
|
|
||||||
if (builtins.isAttrs x)
|
|
||||||
then
|
|
||||||
if !(builtins.hasAttr "tag" x)
|
|
||||||
then
|
|
||||||
attrsets.mapAttrsToList
|
|
||||||
(tag: value: {
|
|
||||||
inherit tag;
|
|
||||||
content = prepass value;
|
|
||||||
})
|
|
||||||
x
|
|
||||||
else if (builtins.hasAttr "content" x)
|
|
||||||
then {
|
|
||||||
tag = x.tag;
|
|
||||||
content = prepass x.content;
|
|
||||||
}
|
|
||||||
else x
|
|
||||||
else if (builtins.isList x)
|
|
||||||
then
|
|
||||||
if (isStrList x)
|
|
||||||
then
|
|
||||||
(builtins.map
|
|
||||||
(content: {
|
|
||||||
tag = "string";
|
|
||||||
inherit content;
|
|
||||||
})
|
|
||||||
x)
|
|
||||||
else builtins.map prepass x
|
|
||||||
else x;
|
|
||||||
|
|
||||||
toXml = tag: x: (toXml' {
|
|
||||||
inherit tag;
|
|
||||||
attrib = {
|
|
||||||
"xmlns:xsi" = "http://www.w3.org/2001/XMLSchema-instance";
|
|
||||||
"xmlns:xsd" = "http://www.w3.org/2001/XMLSchema";
|
|
||||||
};
|
|
||||||
content = prepass x;
|
|
||||||
});
|
|
||||||
in {
|
|
||||||
system.activationScripts = {
|
|
||||||
link-network-xml =
|
|
||||||
lib.stringAfter ["var"]
|
|
||||||
(
|
|
||||||
let
|
|
||||||
storeFile = pkgs.writeText "network.xml" (toXml "NetworkConfiguration" cfg.network);
|
|
||||||
in ''
|
|
||||||
mkdir -p "/var/lib/jellyfin/config"
|
|
||||||
cp -s "${storeFile}" "/var/lib/jellyfin/config/network.xml"
|
|
||||||
''
|
|
||||||
);
|
|
||||||
link-encoding-xml =
|
|
||||||
lib.stringAfter ["var"]
|
|
||||||
(
|
|
||||||
let
|
|
||||||
storeFile = pkgs.writeText "encoding.xml" (toXml "EncodingOptions" cfg.network);
|
|
||||||
in ''
|
|
||||||
mkdir -p "/var/lib/jellyfin/config"
|
|
||||||
cp -s "${storeFile}" "/var/lib/jellyfin/config/encoding.xml"
|
|
||||||
''
|
|
||||||
);
|
|
||||||
link-system-xml =
|
|
||||||
lib.stringAfter ["var"]
|
|
||||||
(
|
|
||||||
let
|
|
||||||
storeFile = pkgs.writeText "system.xml" (toXml "ServerConfiguration" cfg.network);
|
|
||||||
in ''
|
|
||||||
mkdir -p "/var/lib/jellyfin/config"
|
|
||||||
cp -s "${storeFile}" "/var/lib/jellyfin/config/system.xml"
|
|
||||||
''
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,27 @@ in {
|
||||||
../modules/default.nix
|
../modules/default.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
# assertions = let
|
||||||
|
# toXml = (import ../lib {nixpkgs = pkgs;}).toXMLGeneric;
|
||||||
|
# in [
|
||||||
|
# {
|
||||||
|
# assertion =
|
||||||
|
# toXml {tag = "test";}
|
||||||
|
# == ''
|
||||||
|
# <?xml version='1.0' encoding='utf-8'?>
|
||||||
|
# <test />
|
||||||
|
#
|
||||||
|
# '';
|
||||||
|
# message = "Generated XML is incorrect!";
|
||||||
|
# }
|
||||||
|
# {
|
||||||
|
# assertion = false;
|
||||||
|
# message = "lmao";
|
||||||
|
# }
|
||||||
|
# ];
|
||||||
|
|
||||||
|
ass = false;
|
||||||
|
|
||||||
virtualisation.memorySize = 1024 * 2;
|
virtualisation.memorySize = 1024 * 2;
|
||||||
|
|
||||||
services.declarative-jellyfin = {
|
services.declarative-jellyfin = {
|
||||||
|
@ -27,15 +48,12 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# stfu i dont care about python linting
|
|
||||||
# skipLint = true;
|
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
machine.wait_for_unit("multi-user.target");
|
machine.wait_for_unit("multi-user.target");
|
||||||
|
|
||||||
with subtest("Jellyfin URI"):
|
with subtest("Networking"):
|
||||||
# stupid fucking hack because you cant open files in python for some reason
|
# stupid fucking hack because you cant open files in python for some reason
|
||||||
xml = machine.succeed("cat /var/lib/jellyfin/config/network.xml")
|
xml = machine.succeed("cat /var/lib/jellyfin/config/network.xml")
|
||||||
tree = ET.ElementTree(ET.fromstring(xml))
|
tree = ET.ElementTree(ET.fromstring(xml))
|
Loading…
Reference in a new issue