Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
dbus
  • Loading branch information
peterhoeg committed May 15, 2018
1 parent 6db7f92 commit ff571e4
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pkgs/applications/kde/kgpg.nix
Expand Up @@ -4,11 +4,12 @@
akonadi-contacts, gnupg1, karchive, kcodecs, kcontacts, kcoreaddons,
kcrash, kdbusaddons, kiconthemes, kjobwidgets, kio, knotifications, kservice,
ktextwidgets, kxmlgui, kwidgetsaddons, kwindowsystem, qgpgme,
makeUserService, userServiceHook
}:

mkDerivation {
name = "kgpg";
nativeBuildInputs = [ extra-cmake-modules kdoctools makeWrapper ];
nativeBuildInputs = [ extra-cmake-modules kdoctools makeWrapper userServiceHook ];
buildInputs = [
akonadi-contacts gnupg1 karchive kcodecs kcontacts kcoreaddons kcrash
kdbusaddons ki18n kiconthemes kjobwidgets kio knotifications kservice
Expand Down
20 changes: 15 additions & 5 deletions pkgs/applications/misc/hello/default.nix
@@ -1,4 +1,5 @@
{ stdenv, fetchurl }:
{ stdenv, fetchurl,
makeUserService, userServiceHook }:

stdenv.mkDerivation rec {
name = "hello-2.10";
Expand All @@ -8,17 +9,26 @@ stdenv.mkDerivation rec {
sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i";
};

nativeBuildInputs = [ userServiceHook ];

userService = makeUserService {
name = "hello";
dbus = "org.gnu.hello";
exec = "bin/hello";
description = "Hello World!";
};

doCheck = true;

meta = {
meta = with stdenv.lib; {
description = "A program that produces a familiar, friendly greeting";
longDescription = ''
GNU Hello is a program that prints "Hello, world!" when you run it.
It is fully customizable.
'';
homepage = http://www.gnu.org/software/hello/manual/;
license = stdenv.lib.licenses.gpl3Plus;
maintainers = [ stdenv.lib.maintainers.eelco ];
platforms = stdenv.lib.platforms.all;
license = licenses.gpl3Plus;
maintainers = with maintainers; [ eelco ];
platforms = platforms.all;
};
}
12 changes: 11 additions & 1 deletion pkgs/applications/misc/kdeconnect/default.nix
Expand Up @@ -16,6 +16,7 @@
, sshfs
, makeWrapper
, kwayland
, makeUserService, userServiceHook
}:

stdenv.mkDerivation rec {
Expand All @@ -34,10 +35,19 @@ stdenv.mkDerivation rec {
qca-qt5 qtx11extras makeWrapper kwayland
];

nativeBuildInputs = [ extra-cmake-modules kdoctools ];
nativeBuildInputs = [ extra-cmake-modules kdoctools userServiceHook ];

userService = makeUserService {
name = "kdeconnect";
description = "KDE Connect";
dbus = "org.kde.kdeconnectd";
exec = "@out@/lib/libexec/kdeconnectd";
};

postInstall = ''
wrapProgram $out/lib/libexec/kdeconnectd --prefix PATH : ${lib.makeBinPath [ sshfs ]}
for f in ${userService}/* ; do
install -Dm644 $f $out/lib/systemd/user/$(basename $f .service).service
'';

enableParallelBuilding = true;
Expand Down
45 changes: 45 additions & 0 deletions pkgs/build-support/make-userservice/default.nix
@@ -0,0 +1,45 @@
{ stdenv, lib, systemd, writeScript, procps ? null, qt5 ? null }:

{ name
, description
, dbus ? ""
, exec
, environment ? {}
, kdeApp ? false
}:

let
preKde = name: dbus: exec: writeScript "pre-kde-service.sh" ''
#!${stdenv.shell} -eu
# ${lib.getBin systemd}/bin/systemctl --user import-environment QT_SCREEN_SCALE_FACTORS QT_QUICK_CONTROLS_STYLE
# kill non-dbus/service spawned binaries
${lib.getBin qt5.qttools}/bin/qdbus ${dbus} / ${dbus}.main.quit || true
${lib.optionalString stdenv.isLinux ''
${lib.getBin procps}/bin/pkill ${exec} || true
''}
'';

in stdenv.mkDerivation {
name = "${name}.services";
buildCommand = ''
mkdir -p $out
cat > $out/${name}.service <<EOF
[Unit]
Description=${description}
[Service]
${lib.optionalString kdeApp ''
Environment="QT_PLUGIN_PATH="/run/current-system/sw/${qt5.qtbase.qtPluginPrefix}"
Environment="QML2_IMPORT_PATH="/run/current-system/sw/${qt5.qtbase.qtQmlPrefix}"
ExecStartPre=-${preKde name dbus exec}
''}
${lib.optionalString (!(dbus == "")) ''
Type=${if (dbus == "") then "simple" else "dbus"}
BusName=${dbus}
''}
ExecStart=@out@/${exec}
EOF
'';
}
26 changes: 26 additions & 0 deletions pkgs/build-support/setup-hooks/user-service.sh
@@ -0,0 +1,26 @@
preInstallPhases+=" userServicePhase"

patchService() {
mkdir -p $out/lib/systemd/user
for f in $out/*.service ; do
substitute $f $out/lib/systemd/user/$(basename $f .service).service \
--subst-var out
done
}

userServicePhase() {
runHook preUserService

if [[ ${#userServices[@]} -gt 0 ]]; then
echo "multiple services defined"
for f in ${userServices[@]} ; do
patchService $f
done
fi
if [[ -n "${userService}" ]]; then
echo "single service defined"
patchService $userService
fi

runHook postUserService
}
18 changes: 15 additions & 3 deletions pkgs/desktops/plasma-5/powerdevil.nix
@@ -1,17 +1,29 @@
{
mkDerivation,
extra-cmake-modules, kdoctools,
libpthreadstubs,
bluez-qt, kactivities, kauth, kconfig, kdbusaddons, kdelibs4support,
kglobalaccel, ki18n, kidletime, kio, knotifyconfig, kwayland, libkscreen,
networkmanager-qt, plasma-workspace, qtx11extras, solid, udev
networkmanager-qt, plasma-workspace, qtx11extras, solid, udev,
makeUserService, userServiceHook
}:

mkDerivation {
mkDerivation rec {
name = "powerdevil";
nativeBuildInputs = [ extra-cmake-modules kdoctools ];

nativeBuildInputs = [ extra-cmake-modules kdoctools userServiceHook ];

buildInputs = [
kconfig kdbusaddons knotifyconfig solid udev bluez-qt kactivities kauth
kdelibs4support kglobalaccel ki18n kio kidletime kwayland libkscreen
networkmanager-qt plasma-workspace qtx11extras
libpthreadstubs
];

userService = makeUserService {
name = "woot";
dbus = "fef.fefe.fefe";
exec = "@out@/bin/woot";
description = "fefef";
};
}
6 changes: 6 additions & 0 deletions pkgs/top-level/all-packages.nix
Expand Up @@ -83,6 +83,10 @@ with pkgs;
{ name = "auto-patchelf-hook"; deps = [ file ]; }
../build-support/setup-hooks/auto-patchelf.sh;

userServiceHook = makeSetupHook
{ name = "user-service-hook"; deps = [ ]; }
../build-support/setup-hooks/user-service.sh;

ensureNewerSourcesHook = { year }: makeSetupHook {}
(writeScript "ensure-newer-sources-hook.sh" ''
postUnpackHooks+=(_ensureNewerSources)
Expand Down Expand Up @@ -321,6 +325,8 @@ with pkgs;

makeDesktopItem = callPackage ../build-support/make-desktopitem { };

makeUserService = callPackage ../build-support/make-userservice { };

makeAutostartItem = callPackage ../build-support/make-startupitem { };

makeInitrd = { contents, compressor ? "gzip -9n", prepend ? [ ] }:
Expand Down

0 comments on commit ff571e4

Please sign in to comment.