feat(nix): Zen programs. module

This commit is contained in:
Ahmad Ansori Palembani 2024-11-13 08:42:48 +07:00
parent 4141a527e0
commit a17032a2b2
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
4 changed files with 97 additions and 12 deletions

View file

@ -0,0 +1,51 @@
{ config, lib, pkgs, home-manager, ... }:
with lib;
let
inherit (pkgs.stdenv.hostPlatform) isDarwin;
modulePath = [ "programs" "zen" ];
cfg = getAttrFromPath modulePath config;
mkFirefoxModule = import "${home-manager.outPath}/modules/programs/firefox/mkFirefoxModule.nix";
# Because Zen required ZenAvatarPath to be in profiles.ini
# REF: https://github.com/nix-community/home-manager/blob/60bb110917844d354f3c18e05450606a435d2d10/modules/programs/firefox/mkFirefoxModule.nix#L55-L69
profiles = flip mapAttrs' cfg.profiles (_: profile:
nameValuePair "Profile${toString profile.id}" {
Name = profile.name;
Path = if isDarwin then "Profiles/${profile.path}" else profile.path;
IsRelative = 1;
Default = if profile.isDefault then 1 else 0;
ZenAvatarPath = "chrome://browser/content/zen-avatars/avatar-1.svg";
}) // {
General = {
StartWithLastProfile = 1;
} // lib.optionalAttrs (cfg.profileVersion != null) {
Version = cfg.profileVersion;
};
};
profilesIni = generators.toINI { } profiles;
in {
imports = [
(mkFirefoxModule {
inherit modulePath;
name = "Zen Browser";
wrappedPackageName = "zen"; # Imaginary wrappedPackageName so `programs.zen.policies` is added properly
visible = true;
platforms.linux = rec {
vendorPath = ".zen";
configPath = "${vendorPath}";
};
platforms.darwin = rec {
vendorPath = "Library/Application Support/Zen";
configPath = "${vendorPath}";
};
})
];
config = {
home.file."${cfg.configPath}/profiles.ini" = mkForce (mkIf (cfg.profiles != { }) { text = profilesIni; });
};
}

View file

@ -0,0 +1,17 @@
{ pkgs, config, vars, ... }:
{
programs.zen = {
enable = true;
# REF: https://github.com/nix-community/home-manager/blob/342a1d682386d3a1d74f9555cb327f2f311dda6e/modules/programs/firefox/mkFirefoxModule.nix#L264
package = null; # we only want the config
profiles.${config.home.username} = {
id = 0;
isDefault = true;
};
nativeMessagingHosts = [
pkgs.passff-host
];
};
}