Apple's Music app cannot read FLAC, so getting a lossless library onto an iPod requires a converted copy somewhere. This keeps that copy beside the library on a NAS rather than on a laptop, and keeps it current unattended. Walks a source tree and reproduces it path for path as MP3: tags and cover art carried across, already-MP3 sources copied rather than re-encoded, and mirror files whose source has gone deleted along with any directories they emptied. The source library is never written to. Freshness is tracked by modification time -- an encoded file is stamped with its source's mtime, so a file is stale exactly when the two differ. That keeps runs idempotent without a database that could fall out of step with whatever owns the library, which here is Lidarr. Encodes go to a temporary file and are renamed into place, so an interrupted run cannot leave a truncated MP3 that the next run mistakes for finished work. A lock file in the mirror root prevents overlapping passes. Ships as a Python package with a console script, a container image with a TrueNAS Scale compose file, and a Nix flake providing the package, an overlay and a dev shell. The test suite runs real ffmpeg encodes rather than mocks -- the failures worth catching are in what ffmpeg does with tags, cover art and container formats. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
43 lines
1.1 KiB
Nix
43 lines
1.1 KiB
Nix
{
|
|
description = "Maintain a lossy MP3 mirror of a lossless music library";
|
|
|
|
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
|
|
|
outputs =
|
|
{ self, nixpkgs }:
|
|
let
|
|
systems = [
|
|
"x86_64-linux"
|
|
"aarch64-linux"
|
|
"x86_64-darwin"
|
|
"aarch64-darwin"
|
|
];
|
|
forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system});
|
|
in
|
|
{
|
|
overlays.default = final: _prev: {
|
|
music-mirror = final.callPackage ./package.nix { };
|
|
};
|
|
|
|
packages = forAllSystems (pkgs: rec {
|
|
music-mirror = pkgs.callPackage ./package.nix { };
|
|
default = music-mirror;
|
|
});
|
|
|
|
# The package builds only if the test suite passes, so this covers both.
|
|
checks = forAllSystems (pkgs: { inherit (self.packages.${pkgs.system}) music-mirror; });
|
|
|
|
devShells = forAllSystems (pkgs: {
|
|
default = pkgs.mkShellNoCC {
|
|
packages = [
|
|
pkgs.python3
|
|
pkgs.python3Packages.pytest
|
|
pkgs.ffmpeg
|
|
];
|
|
};
|
|
});
|
|
|
|
formatter = forAllSystems (pkgs: pkgs.nixfmt-tree);
|
|
};
|
|
}
|