Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 27 additions & 28 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,35 @@
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};

outputs = { nixpkgs, ... }:
let
systems = nixpkgs.lib.platforms.linux ++ nixpkgs.lib.platforms.darwin;
outputs = {nixpkgs, ...}: let
systems = nixpkgs.lib.platforms.linux ++ nixpkgs.lib.platforms.darwin;

forAllSystems = nixpkgs.lib.genAttrs systems;
in
{
packages = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
zennotes-server = pkgs.callPackage ./packaging/nix/package-server.nix { };
in
{ inherit zennotes-server; }
forAllSystems = nixpkgs.lib.genAttrs systems;
in {
packages = forAllSystems (
system: let
pkgs = nixpkgs.legacyPackages.${system};
zennotes-server = pkgs.callPackage ./packaging/nix/package-server.nix {};
in
{inherit zennotes-server;}
# The desktop package wraps the prebuilt linux-x64 release tarball, so it
# only exists on x86_64-linux; elsewhere the server is the default.
// (
if system == "x86_64-linux" then
let
zennotes-desktop = pkgs.callPackage ./packaging/nix/package-desktop.nix { };
in
{
inherit zennotes-desktop;
default = zennotes-desktop;
}
else
{ default = zennotes-server; }
if system == "x86_64-linux"
then let
zennotes-desktop = pkgs.callPackage ./packaging/nix/package-desktop.nix {};
in {
inherit zennotes-desktop;
default = zennotes-desktop;
}
else {default = zennotes-server;}
)
);
);

devShell = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
devShell = forAllSystems (
system: let
pkgs = nixpkgs.legacyPackages.${system};
in
pkgs.mkShell {
buildInputs = with pkgs; [
go
Expand All @@ -50,6 +46,9 @@
export ELECTRON_SKIP_BINARY_DOWNLOAD=1
'';
}
);
);
nixosModules = {
server = import ./packaging/nix/server-module.nix;
};
};
}
272 changes: 140 additions & 132 deletions packaging/nix/package-desktop.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
wrapGAppsHook3,
copyDesktopItems,
makeDesktopItem,

# Electron / Chromium runtime libraries
alsa-lib,
at-spi2-atk,
Expand All @@ -34,137 +33,146 @@
pango,
systemd,
wayland,
xorg,

libX11,
libXcomposite,
libXcursor,
libXdamage,
libXext,
libXfixes,
libXi,
libXrandr,
libXrender,
libXScrnSaver,
libXtst,
libxcb,
commandLineArgs ? "",
}:
let
}: let
releaseData = lib.importJSON ./release-data.json;
in
# Packaged from the official prebuilt linux-x64 release tarball rather than built
# from source, so `nix run github:ZenNotes/zennotes` downloads the same signed
# binary the AppImage/deb/AUR ship instead of compiling Electron locally. Bump
# `version` + `desktopHash` in release-data.json per release (see README.md).
stdenv.mkDerivation (finalAttrs: {
pname = "zennotes-desktop";
inherit (releaseData) version;

src = fetchurl {
url = "https://github.com/ZenNotes/zennotes/releases/download/v${finalAttrs.version}/ZenNotes-${finalAttrs.version}-linux-x64.tar.gz";
hash = releaseData.desktopHash;
};

sourceRoot = "ZenNotes-${finalAttrs.version}-linux-x64";

nativeBuildInputs = [
autoPatchelfHook
makeWrapper
wrapGAppsHook3
copyDesktopItems
];

buildInputs = [
alsa-lib
at-spi2-atk
at-spi2-core
atk
cairo
cups
dbus
expat
fontconfig
freetype
gdk-pixbuf
glib
gtk3
libdrm
libgbm
libuuid
libxkbcommon
nspr
nss
pango
stdenv.cc.cc # libstdc++
xorg.libX11
xorg.libXcomposite
xorg.libXcursor
xorg.libXdamage
xorg.libXext
xorg.libXfixes
xorg.libXi
xorg.libXrandr
xorg.libXrender
xorg.libXScrnSaver
xorg.libXtst
xorg.libxcb
];

# dlopen'd at runtime (not in DT_NEEDED), so keep them on the wrapper's path.
runtimeDependencies = [
(lib.getLib systemd)
libGL
libnotify
libpulseaudio
wayland
];

dontConfigure = true;
dontBuild = true;
# We invoke makeWrapper manually and splice in gappsWrapperArgs ourselves.
dontWrapGApps = true;

installPhase = ''
runHook preInstall

# The SUID chrome-sandbox can't be made setuid in the Nix store; drop it so
# Electron falls back to the user-namespace sandbox.
rm -f chrome-sandbox

mkdir -p $out/share/zennotes
cp -r . $out/share/zennotes

# Icons + desktop entry ship inside the tarball's arch-extras tree.
for icon in $out/share/zennotes/resources/arch-extras/icons/*.png; do
size="$(basename "$icon" .png)"
install -Dm644 "$icon" "$out/share/icons/hicolor/$size/apps/${finalAttrs.pname}.png"
done

makeWrapper $out/share/zennotes/ZenNotes $out/bin/${finalAttrs.pname} \
"''${gappsWrapperArgs[@]}" \
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto}}" \
${lib.optionalString (commandLineArgs != "") "--add-flags ${lib.escapeShellArg commandLineArgs}"}

runHook postInstall
'';

desktopItems = [
(makeDesktopItem {
name = finalAttrs.pname;
desktopName = "ZenNotes";
exec = "${finalAttrs.pname} %U";
icon = finalAttrs.pname;
comment = "Keyboard-first local Markdown notes";
categories = [
"Office"
"Utility"
"TextEditor"
];
startupWMClass = "ZenNotes";
mimeTypes = [
"text/markdown"
"x-scheme-handler/zennotes"
];
})
];

meta = {
description = "Keyboard-first local Markdown notes with Vim motions, diagrams, and MCP integration (prebuilt binary)";
homepage = "https://zennotes.org/";
changelog = "https://github.com/ZenNotes/zennotes/releases/tag/v${finalAttrs.version}";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ justkrysteq ];
mainProgram = finalAttrs.pname;
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
platforms = [ "x86_64-linux" ];
};
})
# Packaged from the official prebuilt linux-x64 release tarball rather than built
# from source, so `nix run github:ZenNotes/zennotes` downloads the same signed
# binary the AppImage/deb/AUR ship instead of compiling Electron locally. Bump
# `version` + `desktopHash` in release-data.json per release (see README.md).
stdenv.mkDerivation (finalAttrs: {
pname = "zennotes-desktop";
inherit (releaseData) version;

src = fetchurl {
url = "https://github.com/ZenNotes/zennotes/releases/download/v${finalAttrs.version}/ZenNotes-${finalAttrs.version}-linux-x64.tar.gz";
hash = releaseData.desktopHash;
};

sourceRoot = "ZenNotes-${finalAttrs.version}-linux-x64";

nativeBuildInputs = [
autoPatchelfHook
makeWrapper
wrapGAppsHook3
copyDesktopItems
];

buildInputs = [
alsa-lib
at-spi2-atk
at-spi2-core
atk
cairo
cups
dbus
expat
fontconfig
freetype
gdk-pixbuf
glib
gtk3
libdrm
libgbm
libuuid
libxkbcommon
nspr
nss
pango
stdenv.cc.cc # libstdc++
libX11
libXcomposite
libXcursor
libXdamage
libXext
libXfixes
libXi
libXrandr
libXrender
libXScrnSaver
libXtst
libxcb
];

# dlopen'd at runtime (not in DT_NEEDED), so keep them on the wrapper's path.
runtimeDependencies = [
(lib.getLib systemd)
libGL
libnotify
libpulseaudio
wayland
];

dontConfigure = true;
dontBuild = true;
# We invoke makeWrapper manually and splice in gappsWrapperArgs ourselves.
dontWrapGApps = true;

installPhase = ''
runHook preInstall

# The SUID chrome-sandbox can't be made setuid in the Nix store; drop it so
# Electron falls back to the user-namespace sandbox.
rm -f chrome-sandbox

mkdir -p $out/share/zennotes
cp -r . $out/share/zennotes

# Icons + desktop entry ship inside the tarball's arch-extras tree.
for icon in $out/share/zennotes/resources/arch-extras/icons/*.png; do
size="$(basename "$icon" .png)"
install -Dm644 "$icon" "$out/share/icons/hicolor/$size/apps/${finalAttrs.pname}.png"
done

makeWrapper $out/share/zennotes/ZenNotes $out/bin/${finalAttrs.pname} \
"''${gappsWrapperArgs[@]}" \
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto}}" \
${lib.optionalString (commandLineArgs != "") "--add-flags ${lib.escapeShellArg commandLineArgs}"}

runHook postInstall
'';

desktopItems = [
(makeDesktopItem {
name = finalAttrs.pname;
desktopName = "ZenNotes";
exec = "${finalAttrs.pname} %U";
icon = finalAttrs.pname;
comment = "Keyboard-first local Markdown notes";
categories = [
"Office"
"Utility"
"TextEditor"
];
startupWMClass = "ZenNotes";
mimeTypes = [
"text/markdown"
"x-scheme-handler/zennotes"
];
})
];

meta = {
description = "Keyboard-first local Markdown notes with Vim motions, diagrams, and MCP integration (prebuilt binary)";
homepage = "https://zennotes.org/";
changelog = "https://github.com/ZenNotes/zennotes/releases/tag/v${finalAttrs.version}";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [justkrysteq];
mainProgram = finalAttrs.pname;
sourceProvenance = with lib.sourceTypes; [binaryNativeCode];
platforms = ["x86_64-linux"];
};
})
2 changes: 1 addition & 1 deletion packaging/nix/release-data.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "2.14.0",
"hash": "sha256-PdTD3oWxbqJWPwiZTjuYSvnWRn66d8wC73VXWMjQHm8=",
"hash": "sha256-C+doF20/PoCyCtueH9VI3Pb9CA6jOeQP1mGA1Lwd2mQ=",
"npmDepsHash": "sha256-7dchbcGAZm+PlVsES76sYD9NOqeCulEKC7S0zLERvvY=",
"vendorHash": "sha256-ZdOHC2JldvnKSDUFnBUJrKD4F1IWfvYJBksgeDnU9cw=",
"desktopHash": "sha256-eL9UL5+BD4+kNfLBsagSbMAX5mrqlWI6Up2HbM1uvHA="
Expand Down
Loading