refactor: package & config cleanup (#88)

* refactor(package): use package fetchers

builtin fetchers are blocking, therefore also slow. for packaging we
should use the package fetchers

* refactor: build the desktop file as a part of the package

* refactor(default.nix): remove redundant args

* refactor(flake.nix): remove duplicated code & rec

* fix(hm-module)!: typo in mkFireFoxmodule

* fix(hm-module): work with nixpkgs config `allowAliases = false;`

* fix: partial revert of 805c8f56e8

the `lib.mkDefault` was being ignored and the policies would never be
set. perhaps a better thing to do here would be to remove them
completly. otherwise this is the next best thing

* refactor(package): use `hash` over `sha256`

Co-authored-by: Seth Flynn <getchoo@tuta.io>
This commit is contained in:
isabel
2025-08-17 19:28:24 +01:00
committed by Luis Quiñones
parent 0dfccbcf0d
commit dd212be919
6 changed files with 74 additions and 84 deletions

View File

@@ -1,25 +0,0 @@
[Desktop Entry]
Name=Zen Browser
Exec=zen-beta %u
Icon=zen-beta
Type=Application
MimeType=text/html;text/xml;application/xhtml+xml;x-scheme-handler/http;x-scheme-handler/https;application/x-xpinstall;application/pdf;application/json;
StartupWMClass=zen-beta
Categories=Network;WebBrowser;
StartupNotify=true
Terminal=false
X-MultipleArgs=false
Keywords=Internet;WWW;Browser;Web;Explorer;
Actions=new-window;new-private-window;profilemanager;
[Desktop Action new-window]
Name=Open a New Window
Exec=zen-beta %u
[Desktop Action new-private-window]
Name=Open a New Private Window
Exec=zen-beta --private-window %u
[Desktop Action profilemanager]
Name=Open the Profile Manager
Exec=zen-beta --ProfileManager %u

View File

@@ -1,25 +0,0 @@
[Desktop Entry]
Name=Zen Browser (Twilight)
Exec=zen-twilight %u
Icon=zen-twilight
Type=Application
MimeType=text/html;text/xml;application/xhtml+xml;x-scheme-handler/http;x-scheme-handler/https;application/x-xpinstall;application/pdf;application/json;
StartupWMClass=zen-twilight
Categories=Network;WebBrowser;
StartupNotify=true
Terminal=false
X-MultipleArgs=false
Keywords=Internet;WWW;Browser;Web;Explorer;
Actions=new-window;new-private-window;profilemanager;
[Desktop Action new-window]
Name=Open a New Window
Exec=zen-twilight %u
[Desktop Action new-private-window]
Name=Open a New Private Window
Exec=zen-twilight --private-window %u
[Desktop Action profilemanager]
Name=Open the Profile Manager
Exec=zen-twilight --ProfileManager %u

View File

@@ -2,18 +2,16 @@
pkgs ? import <nixpkgs> {},
system ? pkgs.stdenv.hostPlatform.system,
}: let
mkZen = pkgs: name: system: entry: let
mkZen = name: entry: let
variant = (builtins.fromJSON (builtins.readFile ./sources.json)).${entry}.${system};
desktopFile = "zen-${name}.desktop";
in
pkgs.callPackage ./package.nix {
inherit name desktopFile variant;
inherit name variant;
};
in rec {
beta-unwrapped = mkZen pkgs "beta" system "beta";
twilight-unwrapped = mkZen pkgs "twilight" system "twilight";
twilight-official-unwrapped = mkZen pkgs "twilight" system "twilight-official";
beta-unwrapped = mkZen "beta" "beta";
twilight-unwrapped = mkZen "twilight" "twilight";
twilight-official-unwrapped = mkZen "twilight" "twilight-official";
beta = pkgs.wrapFirefox beta-unwrapped {};
twilight = pkgs.wrapFirefox twilight-unwrapped {};

View File

@@ -18,21 +18,16 @@
"aarch64-darwin"
];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
forAllSystems = f:
nixpkgs.lib.genAttrs supportedSystems (
system: f nixpkgs.legacyPackages.${system}
);
in {
packages = forAllSystems (system:
import ./default.nix {
pkgs = nixpkgs.legacyPackages.${system};
});
packages = forAllSystems (pkgs: import ./default.nix {inherit pkgs;});
formatter = forAllSystems (
system: let
pkgs = nixpkgs.legacyPackages.${system};
in
pkgs.alejandra
);
formatter = forAllSystems (pkgs: pkgs.alejandra);
homeModules = rec {
homeModules = {
beta = import ./hm-module.nix {
inherit self home-manager;
name = "beta";
@@ -45,7 +40,7 @@
inherit self home-manager;
name = "twilight-official";
};
default = beta;
default = self.homeModules.beta;
};
};
}

View File

@@ -20,8 +20,8 @@ in {
(mkFirefoxModule {
inherit modulePath;
name = applicationName;
wrappedPackageName = "zen-${name}-unwrapped";
unwrappedPackageName = "zen-${name}";
wrappedPackageName = "zen-${name}";
unwrappedPackageName = "zen-${name}-unwrapped";
visible = true;
platforms = {
linux = {
@@ -38,7 +38,7 @@ in {
config = lib.mkIf config.programs.zen-browser.enable {
programs.zen-browser = {
package =
(pkgs.wrapFirefox (self.packages.${pkgs.stdenv.system}."${name}-unwrapped".override {
(pkgs.wrapFirefox (self.packages.${pkgs.stdenv.hostPlatform.system}."${name}-unwrapped".override {
# Seems like zen uses relative (to the original binary) path to the policies.json file
# and ignores the overrides by pkgs.wrapFirefox
policies = config.programs.zen-browser.policies;
@@ -47,10 +47,9 @@ in {
nativeMessagingHosts = config.programs.zen-browser.nativeMessagingHosts;
};
# This does not work, the package can't build using these policies
policies = lib.mkDefault {
DisableAppUpdate = true;
DisableTelemetry = true;
policies = {
DisableAppUpdate = lib.mkDefault true;
DisableTelemetry = lib.mkDefault true;
};
};
};

View File

@@ -1,7 +1,6 @@
{
name,
variant,
desktopFile,
policies ? {},
lib,
stdenv,
@@ -20,6 +19,10 @@
adwaita-icon-theme,
undmg,
writeText,
fetchurl,
fetchzip,
makeDesktopItem,
copyDesktopItems,
patchelfUnstable, # have to use patchelfUnstable to support --no-clobber-old-sections
applicationName ?
"Zen Browser"
@@ -52,6 +55,8 @@
pname = "zen-${name}-bin-unwrapped";
installDarwin = ''
runHook preInstall
mkdir -p "$out/Applications" "$out/bin"
cp -r *.app "$out/Applications/${applicationName}.app"
ln -s zen "$out/Applications/${applicationName}.app/Contents/MacOS/${binaryName}"
@@ -63,9 +68,13 @@
chmod +x "$out/bin/${binaryName}"
ln -s "$out/bin/${binaryName}" "$out/bin/zen"
runHook postInstall
'';
installLinux = ''
runHook preInstall
# Linux tarball installation
mkdir -p "$prefix/lib/${libName}"
cp -r "$src"/* "$prefix/lib/${libName}"
@@ -74,8 +83,6 @@
ln -s "$prefix/lib/${libName}/zen" "$out/bin/${binaryName}"
ln -s "$out/bin/${binaryName}" "$out/bin/zen"
install -D $desktopSrc/${desktopFile} $out/share/applications/${desktopFile}
mkdir -p "$out/lib/${libName}/distribution"
ln -s ${policiesJson} "$out/lib/${libName}/distribution/policies.json"
@@ -84,6 +91,8 @@
install -D $src/browser/chrome/icons/default/default48.png $out/share/icons/hicolor/48x48/apps/zen-${name}.png
install -D $src/browser/chrome/icons/default/default64.png $out/share/icons/hicolor/64x64/apps/zen-${name}.png
install -D $src/browser/chrome/icons/default/default128.png $out/share/icons/hicolor/128x128/apps/zen-${name}.png
runHook postInstall
'';
in
stdenv.mkDerivation {
@@ -92,18 +101,58 @@ in
src =
if stdenv.hostPlatform.isDarwin
then builtins.fetchurl {inherit (variant) url sha256;}
else builtins.fetchTarball {inherit (variant) url sha256;};
then fetchurl {inherit (variant) url; hash = sha256;}
else fetchzip {inherit (variant) url; hash = sha256;};
sourceRoot = lib.optionalString stdenv.hostPlatform.isDarwin ".";
desktopSrc = ./assets/desktop;
desktopItems = [
(makeDesktopItem {
name = binaryName;
desktopName = "Zen Browser${lib.optionalString (name == "twilight") " Twilight"}";
exec = "${binaryName} %u";
icon = binaryName;
type = "Application";
mimeTypes = [
"text/html"
"text/xml"
"application/xhtml+xml"
"x-scheme-handler/http"
"x-scheme-handler/https"
"application/x-xpinstall"
"application/pdf"
"application/json"
];
startupWMClass = binaryName;
categories = ["Network" "WebBrowser"];
startupNotify = true;
terminal = false;
keywords = ["Internet" "WWW" "Browser" "Web" "Explorer"];
extraConfig.X-MultipleArgs = "false";
actions = {
new-windows = {
name = "Open a New Window";
exec = "${binaryName} %u";
};
new-private-window = {
name = "Open a New Private Window";
exec = "${binaryName} --private-window %u";
};
profilemanager = {
name = "Open the Profile Manager";
exec = "${binaryName} --ProfileManager %u";
};
};
})
];
nativeBuildInputs =
lib.optionals stdenv.hostPlatform.isLinux [
wrapGAppsHook3
autoPatchelfHook
patchelfUnstable
copyDesktopItems
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
undmg
@@ -151,7 +200,6 @@ in
};
meta = {
inherit desktopFile;
description = "Experience tranquillity while browsing the web without people tracking you!";
homepage = "https://zen-browser.app";
downloadPage = "https://zen-browser.app/download/";