pistol: deduplicate platform-dependent files

This commit is contained in:
Benedikt Rips
2026-01-05 23:00:13 +01:00
committed by Austin Horstman
parent 802ce0a7b1
commit a1a11393d9

View File

@@ -9,6 +9,9 @@ let
cfg = config.programs.pistol;
configDir =
if pkgs.stdenv.hostPlatform.isDarwin then "Library/Preferences" else config.xdg.configHome;
configFile = lib.concatStringsSep "\n" (
map (
{
@@ -74,31 +77,23 @@ in
};
config = mkIf cfg.enable (
lib.mkMerge [
config = mkIf cfg.enable {
assertions = [
{
assertions = [
{
assertion = lib.all (
{ fpath, mime, ... }: (fpath != "" && mime == "") || (fpath == "" && mime != "")
) cfg.associations;
message = ''
Each entry in programs.pistol.associations must contain exactly one
of fpath or mime.
'';
}
];
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
assertion = lib.all (
{ fpath, mime, ... }: (fpath != "" && mime == "") || (fpath == "" && mime != "")
) cfg.associations;
message = ''
Each entry in programs.pistol.associations must contain exactly one
of fpath or mime.
'';
}
];
(mkIf (cfg.associations != [ ] && pkgs.stdenv.hostPlatform.isDarwin) {
home.file."Library/Preferences/pistol/pistol.conf".text = configFile;
})
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
(mkIf (cfg.associations != [ ] && !pkgs.stdenv.hostPlatform.isDarwin) {
xdg.configFile."pistol/pistol.conf".text = configFile;
})
]
);
home.file."${configDir}/pistol/pistol.conf" = mkIf (cfg.associations != [ ]) {
text = configFile;
};
};
}