Files
home-manager/tests/modules/programs/alistral/settings-immutable-overridden.nix
Austin Horstman 0b5c5f1672 alistral: add opt-in mutable settings
Keep credentials and application configuration writable while applying
declared values. Seed the required token map and use the same Linux XDG
path in both modes, preserving the macOS location and existing home.file
overrides. Restore byte-identical files before linking read-only settings.
2026-10-04 20:17:45 -05:00

71 lines
2.1 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
configDir =
if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/alistral"
else
".config/alistral";
file = config.home.file."${configDir}/config.json";
cleanup = config.home.activation.alistralImmutableSettings;
expectedTarget = "overridden/alistral.json";
in
{
xdg.configHome = "${config.home.homeDirectory}/custom-config";
programs.alistral = {
enable = true;
settings = {
default_user = "spanish_inquisition";
listenbrainz_url = "https://api.listenbrainz.org/1/";
musicbrainz_url = "http://musicbrainz.org/ws/2";
};
};
home.file."${configDir}/config.json" = {
target = expectedTarget;
source = lib.mkForce (pkgs.writeText "alistral-overridden.json" "{}");
};
assertions = [
{
assertion = !config.programs.alistral.mutableSettings;
message = "Alistral settings must default to immutable settings.";
}
{
assertion = !(config.home.activation ? alistralMutableSettings);
message = "Immutable alistral settings must not register mutable activation.";
}
{
assertion = cleanup.after == [ "writeBoundary" ];
message = "Immutable cleanup must run after writeBoundary.";
}
{
assertion = cleanup.before == [ "linkGeneration" ];
message = "Immutable cleanup must run before linkGeneration.";
}
{
assertion = file.enable;
message = "The immutable alistral settings file must remain enabled.";
}
{
assertion = lib.hasInfix (lib.escapeShellArg expectedTarget) cleanup.data;
message = "Immutable cleanup must use the configured file target.";
}
{
assertion = lib.hasInfix (lib.escapeShellArg (builtins.unsafeDiscardStringContext (toString file.source))) cleanup.data;
message = "Immutable cleanup must use the configured file source.";
}
{
assertion = file.target == expectedTarget;
message = "Immutable alistral settings must use the configured file target.";
}
];
nmt.script = ''
assertFileContent "home-files/${expectedTarget}" ${./override-expected.json}
'';
}