Merge branch 'develop' of pi1.odie.intranet:odie/nixos-combined-flake into develop

This commit is contained in:
Patrick Neff 2024-04-24 05:44:16 +02:00
commit 1b7f26328e
15 changed files with 463 additions and 115 deletions

View File

@ -365,11 +365,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1713077896, "lastModified": 1713166971,
"narHash": "sha256-Noot8H0EZEAFRQWyGxh9ryvhK96xpIqKbh78X447JWs=", "narHash": "sha256-t0P/rKlsE5l1O3O2LYtAelLzp7PeoPCSzsIietQ1hSM=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "630a0992b3627c64e34f179fab68e3d48c6991c0", "rev": "1c43dcfac48a2d622797f7ab741670fdbcf8f609",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -37,9 +37,9 @@
overlays = { overlays = {
kodi = final: prev: { kodi = final: prev: {
kodi-standalone = kodi-standalone =
final.kodi-wayland.passthru.withPackages final.kodi-wayland.withPackages
(kodiPkgs: (kodiPkgs:
with final.kodiPackages; [ with kodiPkgs; [
youtube youtube
pvr-iptvsimple pvr-iptvsimple
keymap keymap

View File

@ -1,16 +1,12 @@
{pkgs, ...}: { _: {
nix = { nix = {
package = pkgs.nix; # package = pkgs.nix;
settings = { settings = {
substituters = [ substituters = [
"http://nixcache.odie.intranet" "http://nixcache.odie.intranet"
"https://nix-community.cachix.org" "https://nix-community.cachix.org"
"https://cache.nixos.org/" "https://cache.nixos.org/"
]; ];
trusted-public-keys = [
"nixcache.odie.intranet:2j5qAVmtBUSZMPWlIRS8Gn0Il9tbotJ9c2y43N0RLKU="
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
}; };
}; };
} }

View File

@ -62,8 +62,8 @@
services = { services = {
nextcloud-client.enable = lib.mkDefault true; nextcloud-client.enable = lib.mkDefault true;
udiskie = { udiskie = {
settings = {
enable = lib.mkDefault true; enable = lib.mkDefault true;
settings = {
program_options = { program_options = {
udisks_version = 2; udisks_version = 2;
tray = true; tray = true;

View File

@ -1,5 +1,6 @@
{ {lib, ...}: with lib; {
imports = [ imports = [
./kodi ./kodi
]; ];
mediacenter.kodi.enable = mkDefault true;
} }

View File

@ -1,30 +1,29 @@
{vars,...}: let {
vars,
mysql,
media,
...
}: let
inherit (vars) timeZone hostName domain; inherit (vars) timeZone hostName domain;
datadirs = "smb://svartalbenheim.odie.intranet/kodi/userdata"; datadirs = "smb://${media.host}/kodi/userdata";
mysql = {
port = 3306;
user = "kodi";
pass = "kodi";
};
in { in {
advancedsettings = {
addons = { addons = {
unknownsourcecs = true; unknownsources = "true";
}; };
services = { services = {
devicename = "${hostName}.${domain}"; devicename = "${hostName}.${domain}";
webserver = true; webserver = "true";
webserverauthentication = false; webserverauthentication = "false";
webserverusername = "kodi"; webserverusername = "kodi";
webserverpassword = "kodi"; webserverpassword = "kodi";
webserverport = 8000; webserverport = "8000";
webserverssl = false; webserverssl = "false";
zeroconf = true; zeroconf = "true";
wsdiscovery = true; wsdiscovery = "true";
upnp = true; upnp = "true";
upnpserver = true; upnpserver = "true";
airplay = true; airplay = "true";
airplayvideosupport = true; airplayvideosupport = "true";
}; };
locale = { locale = {
language = "resource.language.de_de"; language = "resource.language.de_de";
@ -32,19 +31,21 @@ in {
timezone = timeZone; timezone = timeZone;
}; };
lookandfeed = { lookandfeed = {
enablerssfeeds = false; enablerssfeeds = "false";
}; };
videodatabase = { videodatabase = {
inherit (mysql) user pass host;
type = "mysql"; type = "mysql";
inherit (mysql) user pass port; port = builtins.toString mysql.port;
}; };
musicdatabase = { musicdatabase = {
inherit (mysql) user pass host;
type = "mysql"; type = "mysql";
inherit (mysql) user pass port; port = builtins.toString mysql.port;
}; };
videolibrary = { videolibrary = {
importwatchedstate = true; importwatchedstate = "true";
importresumepoint = true; importresumepoint = "true";
}; };
pathsubstitution = { pathsubstitution = {
substitute = [ substitute = [
@ -68,11 +69,6 @@ in {
from = "special://profile/favourites.xml"; from = "special://profile/favourites.xml";
to = "${datadirs}/favourites.xml"; to = "${datadirs}/favourites.xml";
} }
{
from = "special://profile/passwords.xml";
to = "${datadirs}/passwords.xml";
}
]; ];
}; };
};
} }

View File

@ -6,18 +6,59 @@
... ...
}: let }: let
cfg = config.mediacenter.kodi; cfg = config.mediacenter.kodi;
inherit (lib) types;
in in
with lib; { with lib; {
options = { options.mediacenter.kodi = {
mediacenter.kodi = { # enable = mkEnableOption "kodi";
enable = mkEnableOption "kodi"; media = {
host = mkOption {
type = types.str;
default = "media";
};
user = mkOption {
type = types.str;
default = "kodi";
};
pass = mkOption {
type = types.str;
default = "kodi";
}; };
}; };
mysql = {
host = mkOption {
type = types.str;
default = "localhost";
};
port = mkOption {
type = types.int;
default = 3306;
};
user = mkOption {
type = types.str;
default = "kodi";
};
pass = mkOption {
type = types.str;
default = "kodi";
};
};
};
imports = [./kodi.nix]; # import overridden kodi module
config = mkIf cfg.enable { config = mkIf cfg.enable {
programs.kodi = { #programs.kodi = {
enable = true; mediacenter.kodi = {
# enable = true;
package = pkgs.kodi-standalone; package = pkgs.kodi-standalone;
settings = import ./advancedsettings.nix {inherit vars;}; settings = import ./advancedsettings.nix {inherit vars; inherit (cfg) mysql media;};
};
home.file = {
"kodi-passwords.xml" = {
target = ".kodi/userdata/passwords.xml";
text = import ./passwords.nix {
inherit (cfg) media;
};
};
}; };
}; };
} }

View File

@ -0,0 +1,262 @@
{
config,
lib,
pkgs,
...
}:
with lib; let
stylesheetCommonHeader = ''
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
'';
stylesheetCommonFooter = "</xsl:stylesheet>";
stylesheetNestedTags = ''
<xsl:template match="attr[attrs]">
<xsl:variable name="elementName" select="@name"/>
<xsl:element name="{$elementName}">
<xsl:apply-templates select="attrs" />
</xsl:element>
</xsl:template>
<xsl:template match="attr[list[attrs]]">
<xsl:variable name="elementName" select="@name"/>
<xsl:for-each select="list/attrs">
<xsl:element name="{$elementName}">
<xsl:apply-templates select="." />
</xsl:element>
</xsl:for-each>
</xsl:template>
<xsl:template match="attr[not(attrs|list)]">
<xsl:variable name="elementName" select="@name"/>
<xsl:element name="{$elementName}">
<xsl:if test="$elementName='path'">
<!-- needed in sources.xml but will be used for all "path" tags -->
<xsl:attribute name="pathversion">1</xsl:attribute>
</xsl:if>
<xsl:value-of select="*/@value" />
</xsl:element>
</xsl:template>
'';
stylesheetTagsAsSettingWithId = ''
<xsl:template match='attr'>
<setting>
<xsl:attribute name="id">
<xsl:value-of select="@name" />
</xsl:attribute>
<xsl:value-of select="*/@value" />
</setting>
</xsl:template>
'';
stylesheetAdvancedSettingsRootTag = ''
<xsl:template match='/'>
<xsl:comment> Generated by Home Manager. </xsl:comment>
<advancedsettings version="1.0">
<xsl:apply-templates/>
</advancedsettings>
</xsl:template>
'';
stylesheetSourcesRootTag = ''
<xsl:template match='/'>
<xsl:comment> Generated by Home Manager. </xsl:comment>
<sources>
<xsl:apply-templates/>
</sources>
</xsl:template>
'';
stylesheetAddonSettingsRootTag = ''
<xsl:template match='/'>
<xsl:comment> Generated by Home Manager. </xsl:comment>
<settings version="2">
<xsl:apply-templates/>
</settings>
</xsl:template>
'';
attrsetToXml = attrs: name: stylesheet:
pkgs.runCommand name {
# Package splicing for libxslt does not work correctly leading to errors
# when cross-compiling. Use the version from buildPackages explicitly to
# fix this.
nativeBuildInputs = [pkgs.buildPackages.libxslt.bin];
xml = builtins.toXML attrs;
passAsFile = ["xml"];
} ''
xsltproc ${stylesheet} - < "$xmlPath" > "$out"
'';
attrsetToAdvancedSettingsXml = attrs: name: let
stylesheet = builtins.toFile "stylesheet.xsl" ''
${stylesheetCommonHeader}
${stylesheetAdvancedSettingsRootTag}
${stylesheetNestedTags}
${stylesheetCommonFooter}
'';
in
attrsetToXml attrs name stylesheet;
attrsetToSourcesXml = attrs: name: let
stylesheet = builtins.toFile "stylesheet.xsl" ''
${stylesheetCommonHeader}
${stylesheetSourcesRootTag}
${stylesheetNestedTags}
${stylesheetCommonFooter}
'';
in
attrsetToXml attrs name stylesheet;
attrsetToAddonSettingsXml = attrs: name: let
stylesheet = builtins.toFile "stylesheet.xsl" ''
${stylesheetCommonHeader}
${stylesheetAddonSettingsRootTag}
${stylesheetTagsAsSettingWithId}
${stylesheetCommonFooter}
'';
in
attrsetToXml attrs name stylesheet;
in {
meta.maintainers = [hm.maintainers.dwagenk];
options.mediacenter.kodi = {
enable = mkEnableOption "Kodi";
package = mkOption {
type = types.package;
default = pkgs.kodi;
defaultText = literalExpression "pkgs.kodi";
example =
literalExpression
"pkgs.kodi.withPackages (exts: [ exts.pvr-iptvsimple ])";
description = ''
The `kodi` package to use.
Can be used to specify extensions.
'';
};
datadir = mkOption {
type = types.path;
default = "${config.home.homeDirectory}/.kodi";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/.kodi"'';
example = literalExpression ''"''${config.xdg.dataHome}/kodi"'';
description = "Directory to store configuration and metadata.";
};
settings = mkOption {
type = with types; let
valueType =
oneOf [str (attrsOf valueType) (listOf valueType)]
// {
description = "attribute sets or lists of strings";
};
in
nullOr valueType;
default = null;
example = literalExpression ''
{ videolibrary.showemptytvshows = "true"; }
'';
description = ''
Configuration to write to the `advancedsettings.xml`
file in kodis userdata directory. Settings specified here will be
immutable from inside kodi and be hidden from the GUI settings dialog.
See <https://kodi.wiki/view/Advancedsettings.xml> as
reference for how settings need to be specified.
The innermost attributes must be of type str.
'';
};
sources = mkOption {
type = with types; let
valueType =
oneOf [str (attrsOf valueType) (listOf valueType)]
// {
description = "attribute sets or lists of strings";
};
in
nullOr valueType;
default = null;
example = literalExpression ''
{
video = {
default = "movies";
source = [
{ name = "videos"; path = "/path/to/videos"; allowsharing = "true"; }
{ name = "movies"; path = "/path/to/movies"; allowsharing = "true"; }
];
};
}
'';
description = ''
Contents to populate the file `sources.xml` in kodis
userdata directory.
See <https://kodi.wiki/view/Sources.xml> as
reference for how sources need to be specified.
Kodi will still show the dialogs to modify sources in the GUI and they
appear to be mutable. This however is not the case and the sources will
stay as specified via Home Manager.
The innermost attributes must be of type str.
'';
};
addonSettings = mkOption {
type = with types; nullOr (attrsOf (attrsOf str));
default = null;
example = literalExpression ''
{ "service.xbmc.versioncheck".versioncheck_enable = "false"; }
'';
description = ''
Attribute set with the plugin namespace as toplevel key and the plugins
settings as lower level key/value pairs.
Kodi will still show the settings of plugins configured via this
mechanism in the GUI and they appear to be mutable. This however is
not the case and the settings will stay as specified via Home Manager.
'';
};
};
config = let
cfg = config.mediacenter.kodi;
in
mkIf cfg.enable (mkMerge [
{
assertions = [
(lib.hm.assertions.assertPlatform "programs.kodi" pkgs
lib.platforms.linux)
];
home.packages = [cfg.package];
home.sessionVariables = {KODI_DATA = cfg.datadir;};
}
(mkIf (cfg.settings != null) {
home.file."${cfg.datadir}/userdata/advancedsettings.xml".source =
attrsetToAdvancedSettingsXml cfg.settings "kodi-advancedsettings.xml";
})
(mkIf (cfg.sources != null) {
home.file."${cfg.datadir}/userdata/sources.xml".source =
attrsetToSourcesXml cfg.sources "kodi-sources.xml";
})
(mkIf (cfg.addonSettings != null) {
home.file = mapAttrs' (k: v:
attrsets.nameValuePair
"${cfg.datadir}/userdata/addon_data/${k}/settings.xml" {
source = attrsetToAddonSettingsXml v "kodi-addon-${k}-settings.xml";
})
cfg.addonSettings;
})
]);
}

View File

@ -0,0 +1,8 @@
{media,...}: ''
<passwords>
<path>
<from>smb://${media.host}</from>
<to>smb://${media.user}:${media.pass}@${media.host}</to>
</path>
</passwords>
''

View File

@ -5,7 +5,6 @@
substituters = [ substituters = [
"http://nixcache.odie.intranet" "http://nixcache.odie.intranet"
"https://nix-community.cachix.org" "https://nix-community.cachix.org"
"https://cache.nixos.org/"
]; ];
trusted-public-keys = [ trusted-public-keys = [
"nixcache.odie.intranet:2j5qAVmtBUSZMPWlIRS8Gn0Il9tbotJ9c2y43N0RLKU=" "nixcache.odie.intranet:2j5qAVmtBUSZMPWlIRS8Gn0Il9tbotJ9c2y43N0RLKU="

View File

@ -1,10 +1,15 @@
{ config, lib, pkgs, vars, ... }:
let
inherit (vars) hostName;
in
{ {
vars,
...
}: let
inherit (vars) hostName domain;
in {
networking = { networking = {
inherit hostName; inherit hostName domain;
search = [
domain
"fritz.box"
];
firewall.enable = true; firewall.enable = true;
}; };
} }

View File

@ -14,12 +14,35 @@ in
}; };
config = let config = let
user = "kodi"; user = "kodi";
starter = pkgs.callPackage (
{pkgs, kodi-standalone, ...}:
pkgs.writeShellApplication {
name = "kodi-launcher";
runtimeInputs = [kodi-standalone];
text = ''
#!/usr/bin/env bash
while true
do
ping -c1 svartalbenheim.odie.intranet && break
sleep 5
done
while true
do
sleep 1
kodi-standalone
done
'';
}
) {};
in in
lib.mkIf cfg.enable { lib.mkIf cfg.enable {
services.cage = { services.cage = {
inherit user; inherit user;
enable = true; enable = true;
program = "${pkgs.kodi-standalone}/bin/kodi-standalone"; program = "${starter}/bin/kodi-launcher";
}; };
users.users.kodi = { users.users.kodi = {

View File

@ -16,7 +16,17 @@ in {
language.base = vars.locale; language.base = vars.locale;
stateVersion = "23.05"; stateVersion = "23.05";
}; };
mediacenter.kodi.enable = true; mediacenter.kodi = {
enable = true;
media = {
host = "svartalbenheim.odie.intranet";
pass = "Bx5sTkw1Qeg69I9!";
};
mysql = {
host = "svartalbenheim.odie.intranet";
pass = "Bx5sTkw1Qeg69I9!";
};
};
} }
]; ];
} }

View File

@ -7,14 +7,24 @@
outputs.homeManagerModules.development outputs.homeManagerModules.development
outputs.homeManagerModules.games outputs.homeManagerModules.games
outputs.homeManagerModules.binary-cache outputs.homeManagerModules.binary-cache
{ ];
services.picom.enable = false;
desktop = { desktop = {
enable = false; enable = false;
awesome.enable = false;
pcmanfm.enable = false;
thunar.enable = false;
network-manager.enable = false;
}; };
programs = { programs = {
kitty.enable = false; kitty.enable = true;
keepassxc.enable = false;
firefox.enable = false;
}; };
} services = {
]; nextcloud-client.enable = false;
udiskie.enable = false;
picom.enable = false;
};
theme.cursor.enable = false;
theme.gtk.enable = false;
} }

View File

@ -17,9 +17,6 @@
./hardware-configuration.nix ./hardware-configuration.nix
]; ];
services.nginx.enable = true;
services.nix-serve.enable = true;
home-manager.users = home-manager.users =
flakeLib.mkNixosHomeConfiguration { flakeLib.mkNixosHomeConfiguration {
inherit vars system; inherit vars system;