From f057656ed479aeb7fa164448bcf6a097c2e27664 Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Sat, 21 Feb 2026 05:50:11 +0800 Subject: [PATCH 1/2] feat(nix): add yt-meta standalone package Add a runtime-scoped yt-dlp helper package that prints title, uploader, and dd/mm/yyyy upload date for a URL, so metadata extraction can be tested independently of Home Manager. --- nix/outputs/packages.nix | 77 ++++++++++++++++++------ sessions/2026-02-21-yt-dlp-url-script.md | 42 +++++++++++++ 2 files changed, 99 insertions(+), 20 deletions(-) create mode 100644 sessions/2026-02-21-yt-dlp-url-script.md diff --git a/nix/outputs/packages.nix b/nix/outputs/packages.nix index f594501d..2030facb 100644 --- a/nix/outputs/packages.nix +++ b/nix/outputs/packages.nix @@ -3,28 +3,65 @@ perSystem = { pkgs, self', ... }: { - packages.site-bin = pkgs.rustPlatform.buildRustPackage { - name = "site"; - src = config.flake.paths.root + /rs; - cargoLock.lockFile = config.flake.paths.root + /rs/Cargo.lock; - }; - packages.site-image = pkgs.dockerTools.buildLayeredImage { - name = "site"; - tag = "latest"; - contents = [ - self'.packages.site-bin - pkgs.dockerTools.binSh - ]; - config = { - Env = [ - "SITE_CONTENT_DIR=${inputs.site-content}" - "STATIC_DIR=${config.flake.paths.root + /rs/site/static}" + packages = { + yt-meta = pkgs.writeShellApplication { + name = "yt-meta"; + runtimeInputs = with pkgs; [ + yt-dlp + jq + ffmpeg + deno ]; - Entrypoint = [ - "/bin/sh" - "-c" + text = '' + if [ "$#" -ne 1 ]; then + echo "usage: yt-meta " >&2 + exit 1 + fi + + url="$1" + + yt-dlp \ + --js-runtimes deno \ + --remote-components ejs:npm \ + -J "$url" \ + | jq -r ' + . as $v + | $v.title + ", " + + $v.uploader + ", " + + ( + if ($v.upload_date | type) == "string" and ($v.upload_date | test("^[0-9]{8}$")) + then "\($v.upload_date[6:8])/\($v.upload_date[4:6])/\($v.upload_date[0:4])" + else "" + end + ) + ' + ''; + }; + + site-bin = pkgs.rustPlatform.buildRustPackage { + name = "site"; + src = config.flake.paths.root + /rs; + cargoLock.lockFile = config.flake.paths.root + /rs/Cargo.lock; + }; + + site-image = pkgs.dockerTools.buildLayeredImage { + name = "site"; + tag = "latest"; + contents = [ + self'.packages.site-bin + pkgs.dockerTools.binSh ]; - Cmd = [ "/bin/site" ]; + config = { + Env = [ + "SITE_CONTENT_DIR=${inputs.site-content}" + "STATIC_DIR=${config.flake.paths.root + /rs/site/static}" + ]; + Entrypoint = [ + "/bin/sh" + "-c" + ]; + Cmd = [ "/bin/site" ]; + }; }; }; }; diff --git a/sessions/2026-02-21-yt-dlp-url-script.md b/sessions/2026-02-21-yt-dlp-url-script.md new file mode 100644 index 00000000..a70a1bc2 --- /dev/null +++ b/sessions/2026-02-21-yt-dlp-url-script.md @@ -0,0 +1,42 @@ +# 2026-02-21 yt-dlp URL script + +## Task + +User asked for research before implementation: can dependencies be scoped to the command runtime instead of being installed broadly in `home.packages`. + +## Exploration + +- Reviewed current module: `nix/modules/aliases.nix`. +- Reviewed existing script pattern: `scripts/process.sh`. +- Searched web and docs for Nix script builders and runtime dependency handling. +- Verified `writeShellApplication` behavior from Nixpkgs docs and Noogle implementation. + +## Findings + +- `pkgs.writeShellApplication` supports `runtimeInputs` and injects them into `PATH` only for that script runtime. +- This allows adding a single generated package to `home.packages` while not adding each dependency as separate user-facing packages. +- For yt-dlp warnings, `ffmpeg` and a JS runtime (recommended: `deno`) can be provided via `runtimeInputs`. +- For current yt-dlp EJS guidance, runtime alone may not be enough in all packaging contexts; remote EJS components can be enabled via `--remote-components ejs:npm` (with deno/bun) or `ejs:github`. + +## Implementation + +- Implemented a standalone package in `nix/outputs/packages.nix` as `packages.yt-meta` using `pkgs.writeShellApplication`. +- Added runtime-scoped inputs: `yt-dlp`, `jq`, `ffmpeg`, `deno`. +- Script behavior: + - Requires one argument (`yt-meta `). + - Runs `yt-dlp -J` with `--js-runtimes deno` and `--remote-components ejs:npm`. + - Formats output as values-only CSV-like line: `title, uploader, dd/mm/yyyy`. + +## Validation + +- Executed: `nix run .#yt-meta -- "https://www.youtube.com/watch?v=9M7pKi-3o18"`. +- Observed output: + - `How Do Cultures Evolve? - featuring Edward Burnett Tylor — Anthropology Theory #1, a partial perspective, 13/12/2017` +- Date conversion verified from source `upload_date=20171213` to `13/12/2017`. + +## Repo checks + +- Ran `just nice` and `just check`. +- Initial statix warning occurred due to repeated `packages.` keys in `nix/outputs/packages.nix`. +- Fixed by refactoring to a single `packages = { ... };` attrset. +- Re-ran checks successfully. From 0fa747d3b2cece6e8a10a7cbb1700a29e9d223f4 Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Sat, 21 Feb 2026 05:58:36 +0800 Subject: [PATCH 2/2] feat(nix): add yt-meta to home profile Wire the flake-parts package into Home Manager using hostPlatform.system so the command is available on supported architectures after switch. --- nix/modules/aliases.nix | 1 + sessions/2026-02-21-yt-dlp-url-script.md | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/nix/modules/aliases.nix b/nix/modules/aliases.nix index 3faa901c..62be342c 100644 --- a/nix/modules/aliases.nix +++ b/nix/modules/aliases.nix @@ -9,6 +9,7 @@ in { home.packages = [ (pkgs.writeShellScriptBin "process" (lib.fileContents (cfg.paths.root + "/scripts/process.sh"))) + cfg.packages.${pkgs.stdenv.hostPlatform.system}.yt-meta ]; home.shellAliases = { diff --git a/sessions/2026-02-21-yt-dlp-url-script.md b/sessions/2026-02-21-yt-dlp-url-script.md index a70a1bc2..01314fc0 100644 --- a/sessions/2026-02-21-yt-dlp-url-script.md +++ b/sessions/2026-02-21-yt-dlp-url-script.md @@ -40,3 +40,20 @@ User asked for research before implementation: can dependencies be scoped to the - Initial statix warning occurred due to repeated `packages.` keys in `nix/outputs/packages.nix`. - Fixed by refactoring to a single `packages = { ... };` attrset. - Re-ran checks successfully. + +## Home Manager wiring + +- Added `yt-meta` to `home.packages` in `nix/modules/aliases.nix`. +- Used flake-parts transposed package output keyed by host architecture: + - `cfg.packages.${pkgs.stdenv.hostPlatform.system}.yt-meta` +- This keeps one declaration working across `x86_64-linux` and `aarch64-darwin` by selecting the current host system at evaluation time. + +## Live verification + +- Ran `just rb` (including `nh os switch .`) after wiring Home Manager package. +- Switch output showed `yt-meta` integration artifacts (including fish completion derivation). +- Verified command available on native PATH: + - `command -v yt-meta` -> `/home/rafiq/.nix-profile/bin/yt-meta` +- Verified command output from PATH executable: + - `yt-meta "https://www.youtube.com/watch?v=9M7pKi-3o18"` + - `How Do Cultures Evolve? - featuring Edward Burnett Tylor — Anthropology Theory #1, a partial perspective, 13/12/2017`