1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00

programs/nix-search-tv: init

Create the programs/nix-search-tv module, with options to enable,
change settings, and television integration.

Co-authored-by: awwpotato <awwpotato@voidq.com>
This commit is contained in:
Cool-Game-Dev 2025-08-05 12:22:28 -05:00 committed by Austin Horstman
parent 28caf471a6
commit b7ee8deefc
4 changed files with 151 additions and 0 deletions

View file

@ -0,0 +1,86 @@
{
config,
lib,
pkgs,
...
}:
let
jsonFormat = pkgs.formats.json { };
cfg = config.programs.nix-search-tv;
in
{
meta.maintainers = with lib.hm.maintainers; [
poseidon-rises
];
options.programs.nix-search-tv = {
enable = lib.mkEnableOption "nix-search-tv";
package = lib.mkPackageOption pkgs "nix-search-tv" { nullable = true; };
settings = lib.mkOption {
type = jsonFormat.type;
default = { };
description = ''
Configuration written to {file}`$XDG_CONFIG_HOME/nix-search-tv/config.json`.
See <https://github.com/3timeslazy/nix-search-tv?tab=readme-ov-file#configuration>
for the full list of options.
'';
example = lib.literalExpression ''
{
indexes = [ "nixpkgs" "home-manager" "nixos" ];
experimental = {
render_docs_indexes = {
nvf = "https://notashelf.github.io/nvf/options.html";
};
};
}
'';
};
enableTelevisionIntegration = lib.mkOption {
type = lib.types.bool;
default = config.programs.television.enable;
defaultText = lib.literalExpression "config.programs.television.enable";
description = ''
Enables integration with television. Creates a channel through
`programs.television.channels.nix-search-tv`, which are set as defaults
and can be overridden.
See [programs.television.channels](#opt-programs.television.channels)
for more information
'';
example = true;
};
};
config = lib.mkIf cfg.enable {
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
xdg.configFile."nix-search-tv/config.json" = lib.mkIf (cfg.settings != { }) {
source = jsonFormat.generate "config.json" cfg.settings;
};
programs.television.channels.nix-search-tv = lib.mkIf cfg.enableTelevisionIntegration (
let
path = lib.getExe cfg.package;
in
{
metadata = {
name = "nix-search-tv";
description = "Search nix options and packages";
};
source.command = "${path} print";
preview.command = "${path} preview {}";
}
);
assertions = [
{
assertion = cfg.package != null || cfg.enableTelevisionIntegration;
message = "Cannot enable television integration when config.programs.nix-search-tv.package is null.";
}
];
};
}

View file

@ -0,0 +1,39 @@
{ pkgs, ... }:
{
programs.nix-search-tv = {
enable = true;
settings = {
indexes = [
"home-manager"
"nixos"
"nixpkgs"
];
experimental = {
render_docs_indexed = {
nvf = "https://notashelf.github.io/nvf/options.html";
};
};
};
};
nmt.script = ''
assertFileExists home-files/.config/nix-search-tv/config.json
assertFileContent home-files/.config/nix-search-tv/config.json \
${pkgs.writeText "settings-expected" ''
{
"experimental": {
"render_docs_indexed": {
"nvf": "https://notashelf.github.io/nvf/options.html"
}
},
"indexes": [
"home-manager",
"nixos",
"nixpkgs"
]
}
''}
'';
}

View file

@ -0,0 +1,4 @@
{
nix-search-tv-basic-config = ./basic-config.nix;
nix-search-tv-television = ./television.nix;
}

View file

@ -0,0 +1,22 @@
{ lib, pkgs, ... }:
{
programs.television.enable = true;
programs.nix-search-tv.enable = true;
nmt.script = ''
assertFileExists home-files/.config/television/cable/nix-search-tv.toml
assertFileContent home-files/.config/television/cable/nix-search-tv.toml \
${pkgs.writeText "settings-expected" ''
[metadata]
description = "Search nix options and packages"
name = "nix-search-tv"
[preview]
command = "${lib.getExe pkgs.nix-search-tv} preview {}"
[source]
command = "${lib.getExe pkgs.nix-search-tv} print"
''}
'';
}