From 59a4c43e9ba6db24698c112720a58a334117de83 Mon Sep 17 00:00:00 2001 From: Chris Pick Date: Wed, 1 Jan 2025 07:51:47 -0500 Subject: [PATCH] bacon: fix configuration file location on Darwin bacon reads its preferences from a different directory on Darwin. Fix the path to read out of: ~/Library/Application\ Support/org.dystroy.bacon/prefs.toml Linux behavior should be unchanged. --- modules/programs/bacon.nix | 11 +++++++++-- tests/modules/programs/bacon/bacon.nix | 12 +++++++++--- tests/modules/programs/bacon/default.nix | 5 ++++- tests/modules/programs/bacon/empty-config.nix | 15 +++++++++++++++ 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 tests/modules/programs/bacon/empty-config.nix diff --git a/modules/programs/bacon.nix b/modules/programs/bacon.nix index a24d9ffe..ad2e9b5b 100644 --- a/modules/programs/bacon.nix +++ b/modules/programs/bacon.nix @@ -7,6 +7,12 @@ let cfg = config.programs.bacon; settingsFormat = pkgs.formats.toml { }; + + configDir = if pkgs.stdenv.isDarwin then + "Library/Application Support/org.dystroy.bacon" + else + "${config.xdg.configHome}/bacon"; + in { meta.maintainers = [ hm.maintainers.shimunn ]; @@ -34,7 +40,8 @@ in { config = mkIf cfg.enable { home.packages = [ cfg.package ]; - xdg.configFile."bacon/prefs.toml".source = - settingsFormat.generate "prefs.toml" cfg.settings; + home.file."${configDir}/prefs.toml" = mkIf (cfg.settings != { }) { + source = settingsFormat.generate "prefs.toml" cfg.settings; + }; }; } diff --git a/tests/modules/programs/bacon/bacon.nix b/tests/modules/programs/bacon/bacon.nix index 15d98127..6df88456 100644 --- a/tests/modules/programs/bacon/bacon.nix +++ b/tests/modules/programs/bacon/bacon.nix @@ -1,4 +1,10 @@ -{ ... }: { +{ pkgs, ... }: +let + configDir = if pkgs.stdenv.isDarwin then + "Library/Application Support/org.dystroy.bacon" + else + ".config/bacon"; +in { programs.bacon = { enable = true; settings = { @@ -17,7 +23,7 @@ }; test.stubs.bacon = { }; nmt.script = '' - assertFileExists home-files/.config/bacon/prefs.toml - assertFileContent home-files/.config/bacon/prefs.toml ${./expected.toml} + assertFileExists 'home-files/${configDir}/prefs.toml' + assertFileContent 'home-files/${configDir}/prefs.toml' ${./expected.toml} ''; } diff --git a/tests/modules/programs/bacon/default.nix b/tests/modules/programs/bacon/default.nix index 5859a2dd..191483ee 100644 --- a/tests/modules/programs/bacon/default.nix +++ b/tests/modules/programs/bacon/default.nix @@ -1 +1,4 @@ -{ bacon-program = ./bacon.nix; } +{ + bacon-program = ./bacon.nix; + bacon-empty-config = ./empty-config.nix; +} diff --git a/tests/modules/programs/bacon/empty-config.nix b/tests/modules/programs/bacon/empty-config.nix new file mode 100644 index 00000000..51ceb94e --- /dev/null +++ b/tests/modules/programs/bacon/empty-config.nix @@ -0,0 +1,15 @@ +{ pkgs, ... }: +let + configDir = if pkgs.stdenv.isDarwin then + "Library/Application Support/org.dystroy.bacon" + else + ".config/bacon"; +in { + programs.bacon.enable = true; + + test.stubs.bacon = { }; + + nmt.script = '' + assertPathNotExists 'home-files/${configDir}/prefs.toml' + ''; +}