Skip to content

Commit f318ea7

Browse files
authored
feat(wrapperModules.television): init (#528)
1 parent 597b35c commit f318ea7

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

maintainers/default.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,9 @@
106106
github = "appleptree";
107107
githubId = 189892522;
108108
};
109+
allen-liaoo = {
110+
name = "Allen Liao";
111+
github = "allen-liaoo";
112+
githubId = 16383622;
113+
};
109114
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
config,
3+
pkgs,
4+
wlib,
5+
lib,
6+
...
7+
}:
8+
let
9+
types = lib.types;
10+
tomlFmtType = wlib.types.structuredValueWith {
11+
nullable = false;
12+
typeName = "TOML";
13+
};
14+
isPathLike =
15+
x:
16+
builtins.isPath x
17+
|| (lib.isStringLike x && !builtins.isString x)
18+
|| (builtins.isString x && lib.hasPrefix "/" x)
19+
|| lib.isStorePath x;
20+
in
21+
{
22+
imports = [ wlib.modules.default ];
23+
options = {
24+
settings = lib.mkOption {
25+
type = tomlFmtType;
26+
default = { };
27+
description = "Television configuration options.";
28+
};
29+
channels = lib.mkOption {
30+
type = types.lazyAttrsOf (types.either wlib.types.stringable tomlFmtType);
31+
default = { };
32+
description = "Television channels to install.";
33+
};
34+
channelsDir = lib.mkOption {
35+
type = types.str;
36+
readOnly = true;
37+
default = "${placeholder config.configDrvOutput}/${config.binName}-channels";
38+
description = ''
39+
The placeholder for the location of the channels directory.
40+
'';
41+
};
42+
themes = lib.mkOption {
43+
type = types.lazyAttrsOf (types.either wlib.types.stringable tomlFmtType);
44+
default = { };
45+
description = "Themes of television to install.";
46+
};
47+
themesDir = lib.mkOption {
48+
type = types.str;
49+
readOnly = true;
50+
default = "${placeholder config.configDrvOutput}/${config.binName}-themes";
51+
description = ''
52+
The placeholder for the location of the themes directory.
53+
'';
54+
};
55+
configDrvOutput = lib.mkOption {
56+
type = types.str;
57+
default = config.outputName;
58+
description = ''
59+
The derivation output name the generated configuration will be output to.
60+
'';
61+
};
62+
};
63+
config = {
64+
package = lib.mkDefault pkgs.television;
65+
passthru.generatedThemesDir = "${
66+
config.wrapper.${config.configDrvOutput}
67+
}/${baseNameOf config.themesDir}";
68+
passthru.generatedChannelsDir = "${
69+
config.wrapper.${config.configDrvOutput}
70+
}/${baseNameOf config.channelsDir}";
71+
flags = {
72+
"--config-file" = lib.mkIf (config.settings != { }) config.constructFiles.generatedConfig.path;
73+
"--cable-dir" = lib.mkIf (config.channels != { }) config.channelsDir;
74+
};
75+
constructFiles = {
76+
generatedConfig = {
77+
relPath = "${config.binName}-config.toml";
78+
content = builtins.toJSON config.settings;
79+
builder = ''${pkgs.remarshal}/bin/json2toml "$1" "$2"'';
80+
output = config.configDrvOutput;
81+
};
82+
}
83+
// builtins.mapAttrs (n: v: {
84+
key = "channel_${n}";
85+
relPath = lib.mkOverride 0 "${config.binName}-channels/${n}.toml";
86+
output = lib.mkOverride 0 config.configDrvOutput;
87+
${if isPathLike v then null else "content"} = builtins.toJSON v;
88+
"builder" =
89+
if isPathLike v then ''ln -s ${v} "$2"'' else ''${pkgs.remarshal}/bin/json2toml "$1" "$2"'';
90+
}) config.channels
91+
// builtins.mapAttrs (n: v: {
92+
key = "theme_${n}";
93+
relPath = lib.mkOverride 0 "${config.binName}-themes/${n}.toml";
94+
output = lib.mkOverride 0 config.configDrvOutput;
95+
${if isPathLike v then null else "content"} = builtins.toJSON v;
96+
"builder" =
97+
if isPathLike v then ''ln -s ${v} "$2"'' else ''${pkgs.remarshal}/bin/json2toml "$1" "$2"'';
98+
}) config.themes;
99+
meta.maintainers = [ wlib.maintainers.allen-liaoo ];
100+
};
101+
}

0 commit comments

Comments
 (0)