wrap upstart binaries and patch hard-coded paths

This commit is contained in:
Test 2017-02-03 11:03:30 -06:00
parent 4cc9aaccdd
commit b23452d517
3 changed files with 67 additions and 7 deletions

View File

@ -0,0 +1,43 @@
# Useful tool to check syntax of a config file. Upstart needs a dbus
# session, so this script wraps one up and makes the operation not
# require any prior state.
#
# See: http://mwhiteley.com/scripts/2012/12/11/dbus-init-checkconf.html
{stdenv, coreutils, upstart, writeScript, dbus}:
writeScript "upstart-check-config" ''
#!${stdenv.shell}
set -o errexit
set -o nounset
export PATH=${stdenv.lib.makeBinPath [dbus.out upstart coreutils]}:$PATH
if [[ $# -ne 1 ]]
then
echo "Usage: $0 upstart-conf-file" >&2
exit 1
fi
config=$1 && shift
dbus_pid_file=$(mktemp)
exec 4<> $dbus_pid_file
dbus_add_file=$(mktemp)
exec 6<> $dbus_add_file
dbus-daemon --fork --print-pid 4 --print-address 6 --session
function clean {
dbus_pid=$(cat $dbus_pid_file)
if [[ -n $dbus_pid ]]; then
kill $dbus_pid
fi
rm -f $dbus_pid_file $dbus_add_file
}
trap "{ clean; }" EXIT
export DBUS_SESSION_BUS_ADDRESS=$(cat $dbus_add_file)
init-checkconf $config
''

View File

@ -1,17 +1,20 @@
{ stdenv, fetchurl, pkgconfig, dbus, libnih }:
{ stdenv, fetchurl, pkgconfig, dbus, libnih, python, makeWrapper, utillinux
, writeScript }:
let version = "1.5"; in
let
inherit (stdenv.lib) makeBinPath;
version = "1.5";
stdenv.mkDerivation rec {
upstart = stdenv.mkDerivation rec {
name = "upstart-${version}";
src = fetchurl {
url = "http://upstart.ubuntu.com/download/${version}/${name}.tar.gz";
sha256 = "01w4ab6nlisz5blb0an1sxjkndwikr7sjp0cmz4lg00g3n7gahmx";
};
buildInputs = [ pkgconfig dbus libnih ];
buildInputs = [ pkgconfig dbus libnih python makeWrapper];
NIX_CFLAGS_COMPILE =
''
-DSHELL="${stdenv.shell}"
@ -33,6 +36,16 @@ stdenv.mkDerivation rec {
t=$out/etc/bash_completion.d
mkdir -p $t
cp ${./upstart-bash-completion} $t/upstart
# Patch some binaries to refer to the correct binary location.
sed -i "s,/sbin/init,$out/bin/init,g" $out/bin/init-checkconf
sed -i "s,initctl,$out/bin/initctl," $out/bin/initctl2dot
# Add some missing executable permissions, and wrap binaries.
chmod +x $out/bin/init-checkconf $out/bin/init-checkconf
wrapProgram $out/bin/init-checkconf \
--prefix PATH : $out/bin:${makeBinPath [utillinux dbus]}
wrapProgram $out/bin/initctl2dot --prefix PATH : $out/bin
'';
meta = {
@ -40,4 +53,6 @@ stdenv.mkDerivation rec {
description = "An event-based replacement for the /sbin/init daemon";
platforms = stdenv.lib.platforms.linux;
};
}
};
in upstart

View File

@ -11852,6 +11852,8 @@ with pkgs;
upstart = callPackage ../os-specific/linux/upstart { };
upstart-check-config = callPackage ../os-specific/linux/upstart/check-config.nix {};
usbutils = callPackage ../os-specific/linux/usbutils { };
usermount = callPackage ../os-specific/linux/usermount { };