* Refactored some other modules (dbus, hal). svn path=/nixos/trunk/; revision=16652wip/yesman
parent
0ab6be1c81
commit
2331a5140d
@ -0,0 +1,38 @@ |
||||
{pkgs, config, ...}: |
||||
|
||||
with pkgs.lib; |
||||
|
||||
{ |
||||
|
||||
###### interface |
||||
|
||||
options = { |
||||
|
||||
}; |
||||
|
||||
|
||||
###### implementation |
||||
|
||||
config = { |
||||
|
||||
jobs = pkgs.lib.singleton |
||||
{ name = "bluetoothd"; |
||||
|
||||
startOn = "dbus"; |
||||
stopOn = "dbus"; |
||||
|
||||
preStart = |
||||
'' |
||||
mkdir -m 0755 -p /var/lib/bluetooth |
||||
''; |
||||
|
||||
exec = "${pkgs.bluez}/sbin/bluetoothd --nodaemon --debug"; |
||||
}; |
||||
|
||||
environment.systemPackages = [pkgs.bluez pkgs.openobex pkgs.obexftp]; |
||||
|
||||
services.dbus.enable = true; |
||||
services.dbus.packages = [pkgs.bluez]; |
||||
}; |
||||
|
||||
} |
@ -1,119 +1,104 @@ |
||||
# HAL daemon. |
||||
{pkgs, config, ...}: |
||||
|
||||
###### interface |
||||
let |
||||
inherit (pkgs.lib) mkOption; |
||||
with pkgs.lib; |
||||
|
||||
options = { |
||||
services = { |
||||
hal = { |
||||
enable = mkOption { |
||||
default = true; |
||||
description = " |
||||
Whether to start the HAL daemon. |
||||
"; |
||||
}; |
||||
|
||||
extraFdi = mkOption { |
||||
default = []; |
||||
example = [ "/nix/store/.../fdi" ]; |
||||
description = " |
||||
Extend HAL daemon configuration with additionnal paths. |
||||
"; |
||||
}; |
||||
}; |
||||
}; |
||||
}; |
||||
in |
||||
|
||||
###### implementation |
||||
let |
||||
|
||||
cfg = config.services.hal; |
||||
inherit (pkgs.lib) mkIf; |
||||
|
||||
inherit (pkgs) hal; |
||||
|
||||
user = { |
||||
name = "haldaemon"; |
||||
uid = config.ids.uids.haldaemon; |
||||
description = "HAL daemon user"; |
||||
}; |
||||
|
||||
group = { |
||||
name = "haldaemon"; |
||||
gid = config.ids.gids.haldaemon; |
||||
}; |
||||
|
||||
fdi = |
||||
if cfg.extraFdi == [] then |
||||
hal + "/share/hal/fdi" |
||||
"${hal}/share/hal/fdi" |
||||
else |
||||
pkgs.buildEnv { |
||||
name = "hal-fdi"; |
||||
pathsToLink = [ "/preprobe" "/information" "/policy" ]; |
||||
paths = [ (hal + "/share/hal/fdi") ] ++ cfg.extraFdi; |
||||
paths = [ "${hal}/share/hal/fdi" ] ++ cfg.extraFdi; |
||||
}; |
||||
|
||||
job = { |
||||
name = "hal"; |
||||
|
||||
job = '' |
||||
description "HAL daemon" |
||||
in |
||||
|
||||
# !!! TODO: make sure that HAL starts after acpid, |
||||
# otherwise hald-addon-acpi will grab /proc/acpi/event. |
||||
start on ${if config.powerManagement.enable then "acpid" else "dbus"} |
||||
stop on shutdown |
||||
{ |
||||
|
||||
start script |
||||
###### interface |
||||
|
||||
options = { |
||||
|
||||
services.hal = { |
||||
|
||||
enable = mkOption { |
||||
default = true; |
||||
description = " |
||||
Whether to start the HAL daemon. |
||||
"; |
||||
}; |
||||
|
||||
mkdir -m 0755 -p /var/cache/hald |
||||
|
||||
rm -f /var/cache/hald/fdi-cache |
||||
extraFdi = mkOption { |
||||
default = []; |
||||
example = [ "/nix/store/.../fdi" ]; |
||||
description = " |
||||
Extend HAL daemon configuration with additionnal paths. |
||||
"; |
||||
}; |
||||
|
||||
end script |
||||
}; |
||||
|
||||
}; |
||||
|
||||
# HACK ? These environment variables manipulated inside |
||||
# 'src'/hald/mmap_cache.c are used for testing the daemon |
||||
env HAL_FDI_SOURCE_PREPROBE=${fdi}/preprobe |
||||
env HAL_FDI_SOURCE_INFORMATION=${fdi}/information |
||||
env HAL_FDI_SOURCE_POLICY=${fdi}/policy |
||||
|
||||
respawn ${hal}/sbin/hald --daemon=no |
||||
''; |
||||
}; |
||||
in |
||||
###### implementation |
||||
|
||||
config = mkIf cfg.enable { |
||||
|
||||
mkIf cfg.enable { |
||||
require = [ |
||||
# ../upstart-jobs/default.nix # config.services.extraJobs |
||||
# ../system/user.nix # users.* |
||||
# ../upstart-jobs/udev.nix # services.udev.* |
||||
# ../upstart-jobs/dbus.nix # services.dbus.* |
||||
# ? # config.environment.extraPackages |
||||
options |
||||
]; |
||||
|
||||
environment = { |
||||
extraPackages = [hal]; |
||||
}; |
||||
environment.systemPackages = [hal]; |
||||
|
||||
users = { |
||||
extraUsers = [user]; |
||||
extraGroups = [group]; |
||||
}; |
||||
users.extraUsers = singleton |
||||
{ name = "haldaemon"; |
||||
uid = config.ids.uids.haldaemon; |
||||
description = "HAL daemon user"; |
||||
}; |
||||
|
||||
services = { |
||||
extraJobs = [job]; |
||||
users.extraGroups = singleton |
||||
{ name = "haldaemon"; |
||||
gid = config.ids.gids.haldaemon; |
||||
}; |
||||
|
||||
udev = { |
||||
addUdevPkgs = [hal]; |
||||
}; |
||||
jobs = singleton |
||||
{ name = "hal"; |
||||
|
||||
description = "HAL daemon"; |
||||
|
||||
# !!! TODO: make sure that HAL starts after acpid, |
||||
# otherwise hald-addon-acpi will grab /proc/acpi/event. |
||||
startOn = if config.powerManagement.enable then "acpid" else "dbus"; |
||||
stopOn = "shutdown"; |
||||
|
||||
# !!! HACK? These environment variables manipulated inside |
||||
# 'src'/hald/mmap_cache.c are used for testing the daemon |
||||
environment = |
||||
{ HAL_FDI_SOURCE_PREPROBE = "${fdi}/preprobe"; |
||||
HAL_FDI_SOURCE_INFORMATION = "${fdi}/information"; |
||||
HAL_FDI_SOURCE_POLICY = "${fdi}/policy"; |
||||
}; |
||||
|
||||
preStart = |
||||
'' |
||||
mkdir -m 0755 -p /var/cache/hald |
||||
|
||||
rm -f /var/cache/hald/fdi-cache |
||||
''; |
||||
|
||||
exec = "${hal}/sbin/hald --daemon=no"; |
||||
}; |
||||
|
||||
dbus = { |
||||
enable = true; |
||||
services = [hal]; |
||||
}; |
||||
services.udev.addUdevPkgs = [hal]; |
||||
|
||||
services.dbus.enable = true; |
||||
services.dbus.packages = [hal]; |
||||
|
||||
}; |
||||
} |
||||
|
||||
} |
@ -1,116 +1,109 @@ |
||||
# D-Bus system-wide daemon. |
||||
{pkgs, config, ...}: |
||||
|
||||
###### interface |
||||
let |
||||
inherit (pkgs.lib) mkOption; |
||||
|
||||
options = { |
||||
services = { |
||||
dbus = { |
||||
|
||||
enable = mkOption { |
||||
default = true; |
||||
description = " |
||||
Whether to start the D-Bus message bus daemon. It is required |
||||
by the HAL service. |
||||
"; |
||||
merge = pkgs.lib.mergeEnableOption; |
||||
}; |
||||
|
||||
services = mkOption { |
||||
default = []; |
||||
description = ".. fill me .."; |
||||
}; |
||||
|
||||
}; |
||||
}; |
||||
}; |
||||
in |
||||
with pkgs.lib; |
||||
|
||||
###### implementation |
||||
let |
||||
|
||||
cfg = config.services.dbus; |
||||
services = cfg.services; |
||||
inherit (pkgs.lib) mkIf; |
||||
|
||||
inherit (pkgs) stdenv dbus; |
||||
inherit (pkgs) dbus; |
||||
|
||||
homeDir = "/var/run/dbus"; |
||||
|
||||
# Take the standard system configuration file, except that we don't |
||||
# want to fork (Upstart will monitor the daemon). |
||||
configFile = stdenv.mkDerivation { |
||||
configFile = pkgs.stdenv.mkDerivation { |
||||
name = "dbus-conf"; |
||||
buildCommand = " |
||||
buildCommand = '' |
||||
ensureDir $out |
||||
ln -s ${dbus}/etc/dbus-1/system.conf $out/system.conf |
||||
|
||||
# Note: system.conf includes ./system.d (i.e. it has a relative, |
||||
# not absolute path). |
||||
ensureDir $out/system.d |
||||
for i in ${toString services}; do |
||||
for i in ${toString cfg.packages}; do |
||||
ln -s $i/etc/dbus-1/system.d/* $out/system.d/ |
||||
done |
||||
"; |
||||
''; # */ |
||||
}; |
||||
|
||||
user = { |
||||
name = "messagebus"; |
||||
uid = config.ids.uids.messagebus; |
||||
description = "D-Bus system message bus daemon user"; |
||||
home = homeDir; |
||||
}; |
||||
in |
||||
|
||||
job = { |
||||
name = "dbus"; |
||||
|
||||
job = '' |
||||
description "D-Bus system message bus daemon" |
||||
{ |
||||
|
||||
start on startup |
||||
stop on shutdown |
||||
###### interface |
||||
|
||||
start script |
||||
options = { |
||||
|
||||
services.dbus = { |
||||
|
||||
enable = mkOption { |
||||
default = true; |
||||
description = '' |
||||
Whether to start the D-Bus message bus daemon, which is |
||||
required by many other system services and applications. |
||||
''; |
||||
merge = pkgs.lib.mergeEnableOption; |
||||
}; |
||||
|
||||
mkdir -m 0755 -p ${homeDir} |
||||
chown messagebus ${homeDir} |
||||
packages = mkOption { |
||||
default = []; |
||||
description = '' |
||||
Packages whose D-Bus configuration files should be included in |
||||
the configuration of the D-Bus system-wide message bus. |
||||
Specifically, every file in |
||||
<filename><replaceable>pkg</replaceable>/etc/dbus-1/system.d</filename> |
||||
is included. |
||||
''; |
||||
}; |
||||
|
||||
mkdir -m 0755 -p /var/lib/dbus |
||||
${dbus.tools}/bin/dbus-uuidgen --ensure |
||||
|
||||
rm -f ${homeDir}/pid |
||||
${dbus}/bin/dbus-daemon --config-file=${configFile}/system.conf |
||||
end script |
||||
|
||||
respawn sleep 1000000 |
||||
|
||||
stop script |
||||
pid=$(cat ${homeDir}/pid) |
||||
if test -n "$pid"; then |
||||
kill -9 $pid |
||||
fi |
||||
end script |
||||
''; |
||||
}; |
||||
|
||||
}; |
||||
|
||||
in |
||||
|
||||
mkIf cfg.enable { |
||||
require = [ |
||||
# ../upstart-jobs/default.nix # config.services.extraJobs |
||||
# ../system/user.nix # users.* |
||||
# ? # config.environment.extraPackages |
||||
options |
||||
]; |
||||
###### implementation |
||||
|
||||
environment = { |
||||
extraPackages = [dbus.daemon dbus.tools]; |
||||
}; |
||||
config = mkIf cfg.enable { |
||||
|
||||
users = { |
||||
extraUsers = [user]; |
||||
}; |
||||
environment.systemPackages = [dbus.daemon dbus.tools]; |
||||
|
||||
users.extraUsers = singleton |
||||
{ name = "messagebus"; |
||||
uid = config.ids.uids.messagebus; |
||||
description = "D-Bus system message bus daemon user"; |
||||
home = homeDir; |
||||
}; |
||||
|
||||
jobs = singleton |
||||
{ name = "dbus"; |
||||
|
||||
startOn = "startup"; |
||||
stopOn = "shutdown"; |
||||
|
||||
preStart = |
||||
'' |
||||
mkdir -m 0755 -p ${homeDir} |
||||
chown messagebus ${homeDir} |
||||
|
||||
mkdir -m 0755 -p /var/lib/dbus |
||||
${dbus.tools}/bin/dbus-uuidgen --ensure |
||||
|
||||
rm -f ${homeDir}/pid |
||||
# !!! hack - dbus should be running once this job is |
||||
# considered "running"; should be fixable once we have |
||||
# Upstart 0.6. |
||||
${dbus}/bin/dbus-daemon --config-file=${configFile}/system.conf |
||||
''; |
||||
|
||||
postStop = |
||||
'' |
||||
pid=$(cat ${homeDir}/pid) |
||||
if test -n "$pid"; then |
||||
kill -9 $pid |
||||
fi |
||||
''; |
||||
}; |
||||
|
||||
services = { |
||||
extraJobs = [job]; |
||||
}; |
||||
|
||||
} |
||||
|
Loading…
Reference in new issue