Skip to content

Commit 1df94e4

Browse files
committed
radio-active: add module to create config files
Configuration entry similar to; ```nix programs.radio-active.enable = true; ``` By default `ffplay` is used for recording/playback, but that can be changed by applying either of the following; ```nix programs.radio-active.settings.AppConfig.player = "vlc"; programs.radio-active.settings.AppConfig.player = "mpv"; ``` All other configuration options documented by; https://github.com/deep5050/radio-active?tab=readme-ov-file#default-configs maybe applied under the `AppConfig` attribute set. Finally, the `aliases` attribute set allows for defining key/value pares that will generate a `~/.radio-active-alias` of bookmarked stations, for example something like; ```nix programs.radio-active.settings.aliases = { "Deep House Lounge" = "http://198.15.94.34:8006/stream"; }; ``` ... will result in; ``` Deep House Lounge==http://198.15.94.34:8006/stream ``` WARN: must be applied after NixOS/nixpkgs#441029 WARN: requires update of `flake.lock` too
1 parent f35703b commit 1df94e4

File tree

13 files changed

+333
-0
lines changed

13 files changed

+333
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
time = "2025-09-08T21:56:02+00:00";
3+
condition = true;
4+
message = ''
5+
A new module is available: 'programs.radio-active'
6+
7+
`radio-active` is a TUI which enables playing of radio station streams.
8+
9+
This module allows for defining configuration file as well as favorites
10+
list via Nix attribute sets.
11+
'';
12+
}

modules/programs/radio-active.nix

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/**
2+
WARN: must be applied after PR https://github.com/NixOS/nixpkgs/pull/441029
3+
*/
4+
{
5+
config,
6+
lib,
7+
# pkgs,
8+
...
9+
}:
10+
let
11+
pkgs = import /home/s0ands0/git/hub/NixOS/nixpkgs/wt/radio-active { };
12+
13+
inherit (lib)
14+
mapAttrsToList
15+
mkEnableOption
16+
mkIf
17+
mkOption
18+
mkPackageOption
19+
;
20+
21+
inherit (lib.attrsets)
22+
attrByPath
23+
;
24+
25+
inherit (lib.types)
26+
nonEmptyStr
27+
submodule
28+
attrsOf
29+
oneOf
30+
;
31+
32+
inherit (lib.types.numbers)
33+
nonnegative
34+
;
35+
36+
inherit (pkgs.formats)
37+
ini
38+
;
39+
40+
iniFormat = ini { };
41+
42+
cfg = config.programs.radio-active;
43+
in
44+
{
45+
meta.maintainers = [
46+
# lib.maintainers.S0AndS0
47+
## TODO: Trade above for below when `node.nixpkgs.locked.rev` is at or beyond
48+
## 4d48a4e93b9ffbd291b2d9ca3315848e27eed800
49+
{
50+
name = "S0AndS0";
51+
email = "[email protected]";
52+
github = "S0AndS0";
53+
githubId = 4116150;
54+
matrix = "@s0ands0:matrix.org";
55+
}
56+
];
57+
58+
options.programs.radio-active = {
59+
enable = mkEnableOption "Enable installing radio-active and writing configuration file";
60+
61+
package = mkPackageOption pkgs "radio-active" {
62+
nullable = true;
63+
};
64+
65+
settings = mkOption {
66+
default = { };
67+
68+
type = submodule {
69+
options = {
70+
/**
71+
Requires following PR to be merged;
72+
https://github.com/NixOS/nixpkgs/pull/441029
73+
74+
Requires following PR to be merged;
75+
https://github.com/nix-community/home-manager/pull/7793
76+
*/
77+
AppConfig = mkOption {
78+
default = { };
79+
80+
description = ''
81+
Declare-able configurations for radio-active
82+
'';
83+
84+
example = ''
85+
## Input
86+
87+
```nix
88+
programs.radio-active.settings.AppConfig = {
89+
loglevel = "debug";
90+
limit = 41;
91+
sort = "votes";
92+
filter = "none";
93+
volume = 68;
94+
filepath = "/home/{user}/recordings/radioactive/";
95+
filetype = "mp3";
96+
player = "ffplay";
97+
};
98+
```
99+
100+
## Output
101+
102+
```
103+
[AppConfig]
104+
loglevel = debug
105+
limit = 41
106+
sort = votes
107+
filter = none
108+
volume = 68
109+
filepath = /home/{user}/recordings/radioactive/
110+
filetype = mp3
111+
player = ffplay
112+
```
113+
'';
114+
115+
type = attrsOf (oneOf [nonEmptyStr nonnegative]);
116+
};
117+
118+
aliases = mkOption {
119+
description = ''
120+
Key/value pairs where the key is name of radio station and value is URL
121+
'';
122+
123+
example = ''
124+
## Input
125+
126+
```nix
127+
programs.radio-active.aliases = {
128+
"Deep House Lounge" = "http://198.15.94.34:8006/stream";
129+
};
130+
```
131+
132+
## Output
133+
134+
```
135+
Deep House Lounge==http://198.15.94.34:8006/stream
136+
```
137+
'';
138+
139+
default = { };
140+
type = attrsOf nonEmptyStr;
141+
};
142+
};
143+
};
144+
};
145+
};
146+
147+
config = mkIf cfg.enable {
148+
## TODO: test that dependency `postPatch` modifications works at runtime
149+
home.packages =
150+
let
151+
player = attrByPath ["settings" "AppConfig" "player"] "ffplay" cfg;
152+
153+
radio-active =
154+
if player == "ffplay" then
155+
pkgs.radio-active
156+
else if player == "mpv" then
157+
pkgs.radio-active.overrideAttrs (
158+
finalAttrs: previousAttrs: {
159+
postPatch = ''
160+
${previousAttrs.postPatch}
161+
162+
substituteInPlace radioactive/mpv.py \
163+
--replace-fail 'self.exe_path = which(self.program_name)' \
164+
'self.exe_path = "${lib.getExe pkgs.mpv}"'
165+
'';
166+
}
167+
)
168+
else if player == "vlc" then
169+
pkgs.radio-active.overrideAttrs (
170+
finalAttrs: previousAttrs: {
171+
postPatch = ''
172+
${previousAttrs.postPatch}
173+
174+
substituteInPlace radioactive/vlc.py \
175+
--replace-fail 'self.exe_path = which(self.program_name)' \
176+
'self.exe_path = "${lib.getExe pkgs.vlc}"'
177+
'';
178+
}
179+
)
180+
else
181+
lib.warn ''
182+
Unknown player defined in `config.programs.radio-active.AppConfig.player`
183+
'' pkgs.radio-active;
184+
in
185+
mkIf (cfg.package != null) [
186+
radio-active
187+
];
188+
189+
xdg.configFile."radio-active/configs.ini" =
190+
lib.mkIf (cfg.settings != { } && cfg.settings.AppConfig != { })
191+
{
192+
source = iniFormat.generate "radio-active-config" {
193+
inherit (cfg.settings) AppConfig;
194+
};
195+
};
196+
197+
home.file."radio-active-alias" = mkIf (cfg.settings != { } && cfg.settings.aliases != { }) {
198+
text = ''
199+
${builtins.concatStringsSep "\n" (
200+
mapAttrsToList (name: value: "${name}==${value}") cfg.settings.aliases
201+
)}
202+
'';
203+
target = "${config.home.homeDirectory}/.radio-active-alias";
204+
};
205+
};
206+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[AppConfig]
2+
filepath=/mnt/{user}/recordings/radioactive/
3+
filetype=auto
4+
filter=name=shows
5+
limit=41
6+
loglevel=debug
7+
player=ffplay
8+
sort=random
9+
volume=68
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
programs.radio-active = {
3+
enable = true;
4+
5+
settings.AppConfig = {
6+
filepath = "/mnt/{user}/recordings/radioactive/";
7+
filetype = "auto";
8+
filter = "name=shows";
9+
limit = 41;
10+
loglevel = "debug";
11+
player = "ffplay";
12+
sort = "random";
13+
volume = 68;
14+
};
15+
};
16+
17+
nmt.script = ''
18+
assertFileExists home-files/.config/radio-active/configs.ini
19+
assertFileContent home-files/.config/radio-active/configs.ini \
20+
${./AppConfig.ini}
21+
'';
22+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[AppConfig]
2+
filepath=/home/{user}/recordings/radioactive/
3+
filetype=mp3
4+
filter=none
5+
limit=41
6+
loglevel=debug
7+
player=ffplay
8+
sort=votes
9+
volume=68
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
programs.radio-active = {
3+
enable = true;
4+
5+
settings.AppConfig = {
6+
filepath = "/home/{user}/recordings/radioactive/";
7+
filetype = "mp3";
8+
filter = "none";
9+
limit = 41;
10+
loglevel = "debug";
11+
player = "ffplay";
12+
sort = "votes";
13+
volume = 68;
14+
};
15+
};
16+
17+
nmt.script = ''
18+
assertFileExists home-files/.config/radio-active/configs.ini
19+
assertFileContent home-files/.config/radio-active/configs.ini \
20+
${./AppConfig_all.ini}
21+
'';
22+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[AppConfig]
2+
player=mpv
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
programs.radio-active = {
3+
enable = true;
4+
5+
settings.AppConfig.player = "mpv";
6+
};
7+
8+
nmt.script = ''
9+
assertFileExists home-files/.config/radio-active/configs.ini
10+
assertFileContent home-files/.config/radio-active/configs.ini \
11+
${./AppConfig_player_mpv.ini}
12+
'';
13+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[AppConfig]
2+
player=vlc
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
programs.radio-active = {
3+
enable = true;
4+
5+
settings.AppConfig.player = "vlc";
6+
};
7+
8+
nmt.script = ''
9+
assertFileExists home-files/.config/radio-active/configs.ini
10+
assertFileContent home-files/.config/radio-active/configs.ini \
11+
${./AppConfig_player_vlc.ini}
12+
'';
13+
}

0 commit comments

Comments
 (0)