From b23452d517bde87aec3c3a2310c089472072ebd6 Mon Sep 17 00:00:00 2001 From: Test Date: Fri, 3 Feb 2017 11:03:30 -0600 Subject: [PATCH] wrap upstart binaries and patch hard-coded paths --- .../linux/upstart/check-config.nix | 43 +++++++++++++++++++ pkgs/os-specific/linux/upstart/default.nix | 29 ++++++++++--- pkgs/top-level/all-packages.nix | 2 + 3 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 pkgs/os-specific/linux/upstart/check-config.nix diff --git a/pkgs/os-specific/linux/upstart/check-config.nix b/pkgs/os-specific/linux/upstart/check-config.nix new file mode 100644 index 00000000000..5803b4ed833 --- /dev/null +++ b/pkgs/os-specific/linux/upstart/check-config.nix @@ -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 +'' diff --git a/pkgs/os-specific/linux/upstart/default.nix b/pkgs/os-specific/linux/upstart/default.nix index 938f4edd2fb..d5b9be34d9c 100644 --- a/pkgs/os-specific/linux/upstart/default.nix +++ b/pkgs/os-specific/linux/upstart/default.nix @@ -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 diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b0ae2343e23..cf5a17f0e68 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -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 { };