mirror of
https://github.com/nix-community/home-manager.git
synced 2026-12-06 04:40:17 +00:00
Readest keeps settings.json in Tauri's app config directory, which on Darwin is ~/Library/Application Support/com.bilingify.readest rather than $XDG_CONFIG_HOME/com.bilingify.readest. The module wrote to the latter, so declared settings had no effect on Darwin.
106 lines
2.9 KiB
Nix
106 lines
2.9 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
|
|
{
|
|
programs.readest = {
|
|
enable = true;
|
|
package = config.lib.test.mkStubPackage { name = "readest"; };
|
|
settings = {
|
|
telemetryEnabled = false;
|
|
libraryViewMode = "grid";
|
|
globalViewSettings = {
|
|
theme = "dark";
|
|
defaultFontSize = 18;
|
|
};
|
|
enabledPlugins = [ "dictionary" ];
|
|
};
|
|
};
|
|
|
|
home.homeDirectory = lib.mkForce "/@TMPDIR@/hm-user";
|
|
|
|
nmt.script =
|
|
let
|
|
preexistingSettings = builtins.toFile "readest-preexisting-settings.json" ''
|
|
{
|
|
"telemetryEnabled": true,
|
|
"libraryViewMode": "list",
|
|
"globalViewSettings": {
|
|
"theme": "light",
|
|
"lineHeight": 1.5
|
|
},
|
|
"appOwnedSetting": "preserved",
|
|
"enabledPlugins": ["translator", "notes"]
|
|
}
|
|
'';
|
|
|
|
expectedInitialSettings = builtins.toFile "readest-expected-initial-settings.json" ''
|
|
{
|
|
"enabledPlugins": [
|
|
"dictionary"
|
|
],
|
|
"globalViewSettings": {
|
|
"defaultFontSize": 18,
|
|
"theme": "dark"
|
|
},
|
|
"libraryViewMode": "grid",
|
|
"telemetryEnabled": false
|
|
}
|
|
'';
|
|
|
|
expectedMergedSettings = builtins.toFile "readest-expected-merged-settings.json" ''
|
|
{
|
|
"appOwnedSetting": "preserved",
|
|
"enabledPlugins": [
|
|
"dictionary"
|
|
],
|
|
"globalViewSettings": {
|
|
"defaultFontSize": 18,
|
|
"lineHeight": 1.5,
|
|
"theme": "dark"
|
|
},
|
|
"libraryViewMode": "grid",
|
|
"telemetryEnabled": false
|
|
}
|
|
'';
|
|
|
|
settingsPath =
|
|
if pkgs.stdenv.hostPlatform.isDarwin then
|
|
"Library/Application Support/com.bilingify.readest/settings.json"
|
|
else
|
|
".config/com.bilingify.readest/settings.json";
|
|
activationScript = pkgs.writeScript "readest-settings-activation" (
|
|
config.home.activation.readestSettings.data
|
|
);
|
|
in
|
|
''
|
|
export HOME=$TMPDIR/hm-user
|
|
export XDG_CONFIG_HOME=$HOME/.config
|
|
|
|
substitute ${activationScript} $TMPDIR/readest-activate --subst-var TMPDIR
|
|
chmod +x $TMPDIR/readest-activate
|
|
function run() { "$@"; }
|
|
function verboseEcho() { :; }
|
|
function assertJsonEqual() {
|
|
diff -u \
|
|
<(${lib.getExe pkgs.jq} --sort-keys . "$1") \
|
|
<(${lib.getExe pkgs.jq} --sort-keys . "$2")
|
|
}
|
|
|
|
source $TMPDIR/readest-activate
|
|
assertJsonEqual "$HOME/${settingsPath}" "${expectedInitialSettings}"
|
|
[[ "$(stat -c '%a' "$HOME/${settingsPath}")" == 600 ]] \
|
|
|| fail "Readest settings should have mode 600"
|
|
|
|
cat ${preexistingSettings} > "$HOME/${settingsPath}"
|
|
source $TMPDIR/readest-activate
|
|
assertJsonEqual "$HOME/${settingsPath}" "${expectedMergedSettings}"
|
|
|
|
source $TMPDIR/readest-activate
|
|
assertJsonEqual "$HOME/${settingsPath}" "${expectedMergedSettings}"
|
|
'';
|
|
}
|