Skip to content

Commit

Permalink
nix setup: initial build
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarewk committed Nov 20, 2023
1 parent 10306b8 commit 30a10ee
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 0 deletions.
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ pkgs ? import <nixpkgs> { }, ... }: pkgs.callPackage ./nix { }
63 changes: 63 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

outputs = inputs@{ self, flake-parts, ... }: flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
flake.overlays.default = final: prev: {
ulauncher6 = final.callPackage ./. { };
ulauncher6-noxorg = final.ulauncher6.override {
withXorg = false;
};
};
perSystem = { config, self', inputs', pkgs, system, ... }: {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
packages.default = pkgs.ulauncher6;
packages.ulauncher6 = pkgs.ulauncher6;
packages.ulauncher6-noxorg = pkgs.ulauncher6-noxorg;
};
};
}
155 changes: 155 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# based off https://github.com/NixOS/nixpkgs/blob/e44462d6021bfe23dfb24b775cc7c390844f773d/pkgs/applications/misc/ulauncher/default.nix#L4-L4
{ lib
, fetchFromGitHub
, gdk-pixbuf
, glib
, git
, gnome
, gobject-introspection
, gtk-layer-shell
, gtk3
, intltool
, libX11
, libappindicator
, librsvg
, libwnck
, mkYarnPackage
, nix-update-script
, python3Packages
, systemd
, webkitgtk
, wrapGAppsHook
, xvfb-run
, xdg-utils
, withXorg ? true
}:
let
pname = "ulauncher";
version = "v6";
isInRepo = builtins.pathExists ../ulauncher/__init__.py;
src =
if isInRepo then ../.
# `nixpkgs` stub to get less modifications
else
fetchFromGitHub {
owner = "Ulauncher";
repo = "Ulauncher";
rev = "4955e1dd469825bc26015a8d16b73673bb36cc91";
sha256 = "sha256-MuFaU1Cm1dNffSPxYqU0arOtOIUlAuqNgbdl5T9J1VE=";
};
preferences = mkYarnPackage {
name = "${pname}-${version}-ulauncher-prefs";
src = if isInRepo then ../preferences-src else "${src}/preferences-src";
postPatch = ''
substituteInPlace webpack.build.conf.js \
--replace "__dirname, '../data/preferences" "__dirname, 'dist"
'';
buildPhase = ''yarn --offline run build'';
installPhase = ''mv -T deps/ulauncher-prefs/dist $out'';
distPhase = "true";
};
in
python3Packages.buildPythonPackage {
inherit version pname src;

nativeBuildInputs = with python3Packages; [
gdk-pixbuf
gobject-introspection
intltool
wrapGAppsHook
];

buildInputs = [
gnome.adwaita-icon-theme
gtk-layer-shell
libappindicator
librsvg
webkitgtk
] ++ lib.optionals withXorg [
libwnck
];

# runtime dependencies (binaries prepended to PATH)
propagatedBuildInputs = with python3Packages; [
glib
gtk3
levenshtein
mock
pycairo
pygobject3
requests
git
xdg-utils
];

nativeCheckInputs = with python3Packages; [
mock
pytest
pytest-mock
xvfb-run
];

patches = [
./fix-assets.patch
];

postPatch = ''
substituteInPlace setup.py --subst-var out
patchShebangs bin/ulauncher-toggle
substituteInPlace \
bin/ulauncher-toggle \
io.ulauncher.Ulauncher.desktop \
--replace gapplication ${glib}/bin/gapplication
substitute \
ulauncher.service \
io.ulauncher.Ulauncher.service \
--replace "/usr" "$out"
ln -s "${preferences}" data/preferences
'';

# https://github.com/Ulauncher/Ulauncher/issues/390
doCheck = false;

preCheck = ''
export PYTHONPATH=$PYTHONPATH:$out/${python3Packages.python.sitePackages}
'';

# Simple translation of
# - https://github.com/Ulauncher/Ulauncher/blob/f5a601bdca75198a6a31b9d84433496b63530e74/test
checkPhase = ''
runHook preCheck
# skip tests in invocation that handle paths that
# aren't nix friendly (i think)
xvfb-run -s '-screen 0 1024x768x16' \
pytest -k 'not TestPath and not test_handle_key_press_event' tests
runHook postCheck
'';

# do not double wrap
dontWrapGApps = true;
preFixup = ''
makeWrapperArgs+=(
"''${gappsWrapperArgs[@]}"
${lib.optionalString withXorg ''--prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ libX11 ]}"''}
--prefix WEBKIT_DISABLE_COMPOSITING_MODE : "1"
)
'';

passthru = {
updateScript = nix-update-script { };
};


meta = with lib; {
description = "A fast application launcher for Linux, written in Python, using GTK";
homepage = "https://ulauncher.io/";
license = licenses.gpl3;
platforms = platforms.linux;
maintainers = with maintainers; [ aaronjanse sebtm ];
};
}
13 changes: 13 additions & 0 deletions nix/fix-assets.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/setup.py b/setup.py
index 525bec0f..3fdb2146 100755
--- a/setup.py
+++ b/setup.py
@@ -82,7 +82,7 @@ class build_wrapper(build_py, Command):
[
"import gi",
f"gi.require_versions({json.dumps(dict(config['gi_versions']))})",
- f"ASSETS = '{sys.prefix}/share/ulauncher'",
+ f"ASSETS = '@out@/share/ulauncher'",
f"VERSION = '{VERSION}'",
]
)

0 comments on commit 30a10ee

Please sign in to comment.