* Added a module for the bluetooth daemon.

* Refactored some other modules (dbus, hal).

svn path=/nixos/trunk/; revision=16652
This commit is contained in:
Eelco Dolstra 2009-08-10 18:25:09 +00:00
parent 0ab6be1c81
commit 2331a5140d
7 changed files with 209 additions and 188 deletions

View file

@ -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];
};
}

View file

@ -1,119 +1,104 @@
# HAL daemon.
{pkgs, config, ...}:
###### interface
with pkgs.lib;
let
inherit (pkgs.lib) mkOption;
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"
# !!! 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
mkdir -m 0755 -p /var/cache/hald
rm -f /var/cache/hald/fdi-cache
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
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];
};
###### interface
options = {
services.hal = {
enable = mkOption {
default = true;
description = "
Whether to start the HAL daemon.
";
};
users = {
extraUsers = [user];
extraGroups = [group];
};
extraFdi = mkOption {
default = [];
example = [ "/nix/store/.../fdi" ];
description = "
Extend HAL daemon configuration with additionnal paths.
";
};
services = {
extraJobs = [job];
udev = {
addUdevPkgs = [hal];
};
dbus = {
enable = true;
services = [hal];
};
};
}
###### implementation
config = mkIf cfg.enable {
environment.systemPackages = [hal];
users.extraUsers = singleton
{ name = "haldaemon";
uid = config.ids.uids.haldaemon;
description = "HAL daemon user";
};
users.extraGroups = singleton
{ name = "haldaemon";
gid = config.ids.gids.haldaemon;
};
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";
};
services.udev.addUdevPkgs = [hal];
services.dbus.enable = true;
services.dbus.packages = [hal];
};
}

View file

@ -58,7 +58,7 @@ mkIf cfg.enable {
dbus = {
enable = true;
services = [pkgs.disnix];
packages = [pkgs.disnix];
};
};
}

View file

@ -153,7 +153,7 @@ mkIf cfg.enable {
dbus = {
enable = true;
services = [avahi];
packages = [avahi];
};
};
}

View file

@ -68,7 +68,12 @@ in
) config.networking.firewall.allowedTCPPorts
}
# Drop everything else.
# Accept multicast. Not a big security risk since
# probably nobody is listening anyway.
${iptables} -A INPUT -d 224.0.0.0/4 -j ACCEPT
# Drop everything else.
${iptables} -A INPUT -j LOG --log-level info --log-prefix "firewall: "
${iptables} -A INPUT -j DROP
'';

View file

@ -53,7 +53,7 @@ mkIf cfg.enable {
dbus = {
enable = true;
services = [ConsoleKit];
packages = [ConsoleKit];
};
};
}

View file

@ -1,116 +1,109 @@
# D-Bus system-wide daemon.
{pkgs, config, ...}:
###### interface
with pkgs.lib;
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
###### 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;
};
job = {
name = "dbus";
job = ''
description "D-Bus system message bus daemon"
start on startup
stop on shutdown
start script
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
${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
];
{
environment = {
extraPackages = [dbus.daemon dbus.tools];
###### interface
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;
};
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.
'';
};
};
};
users = {
extraUsers = [user];
};
services = {
extraJobs = [job];
###### implementation
config = mkIf cfg.enable {
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
'';
};
};
}