summary refs log tree commit diff
path: root/modules/services/networking/avahi-daemon.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2009-10-12 16:36:19 +0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2009-10-12 16:36:19 +0000
commite91d882a946fc736f62235296e77c139cee7d9b3 (patch)
treee220488319f0cc28aafb01ca26809429eeaf7f82 /modules/services/networking/avahi-daemon.nix
parent4a78ef25e73da292d060a2afde0c00980a22b2ac (diff)
downloadnixpkgs-e91d882a946fc736f62235296e77c139cee7d9b3.tar
nixpkgs-e91d882a946fc736f62235296e77c139cee7d9b3.tar.gz
nixpkgs-e91d882a946fc736f62235296e77c139cee7d9b3.tar.bz2
nixpkgs-e91d882a946fc736f62235296e77c139cee7d9b3.tar.lz
nixpkgs-e91d882a946fc736f62235296e77c139cee7d9b3.tar.xz
nixpkgs-e91d882a946fc736f62235296e77c139cee7d9b3.tar.zst
nixpkgs-e91d882a946fc736f62235296e77c139cee7d9b3.zip
* Converted modules that were still using the old (concrete syntax)
  style of declaring Upstart jobs.  While at it, converted them to the
  current NixOS module style and improved some option descriptions.
  Hopefully I didn't break too much :-)

svn path=/nixos/trunk/; revision=17761
Diffstat (limited to 'modules/services/networking/avahi-daemon.nix')
-rw-r--r--modules/services/networking/avahi-daemon.nix236
1 files changed, 109 insertions, 127 deletions
diff --git a/modules/services/networking/avahi-daemon.nix b/modules/services/networking/avahi-daemon.nix
index ff01a755f6a..34e2a83754d 100644
--- a/modules/services/networking/avahi-daemon.nix
+++ b/modules/services/networking/avahi-daemon.nix
@@ -1,86 +1,18 @@
 # Avahi daemon.
-{pkgs, config, ...}:
+{ config, pkgs, ... }:
 
-###### interface
-let
-  inherit (pkgs.lib) mkOption;
-
-  options = {
-    services = {
-      avahi = {
-
-        enable = mkOption {
-          default = false;
-          description = ''
-            Whether to run the Avahi daemon, which allows Avahi clients
-            to use Avahi's service discovery facilities and also allows
-            the local machine to advertise its presence and services
-            (through the mDNS responder implemented by `avahi-daemon').
-          '';
-        };
+with pkgs.lib;
 
-        hostName = mkOption {
-          default = config.networking.hostName;
-          description = ''Host name advertised on the LAN.'';
-        };
-
-        browseDomains = mkOption {
-          default = [ "0pointer.de" "zeroconf.org" ];
-          description = ''
-            List of non-local DNS domains to be browsed.
-          '';
-        };
-
-        ipv4 = mkOption {
-          default = true;
-          description = ''Whether to use IPv4'';
-        };
-
-        ipv6 = mkOption {
-          default = false;
-          description = ''Whether to use IPv6'';
-        };
-
-        wideArea = mkOption {
-          default = true;
-          description = ''Whether to enable wide-area service discovery.'';
-        };
-
-        publishing = mkOption {
-          default = true;
-          description = ''Whether to allow publishing.'';
-        };
-
-        nssmdns = mkOption {
-          default = false;
-          description = ''
-            Whether to enable the mDNS NSS (Name Service Switch) plug-in.
-            Enabling it allows applications to resolve names in the `.local'
-            domain by transparently querying the Avahi daemon.
-
-            Warning: Currently, enabling this option breaks DNS lookups after
-            a `nixos-rebuild'.  This is because `/etc/nsswitch.conf' is
-            updated to use `nss-mdns' but `libnss_mdns' is not in
-            applications' `LD_LIBRARY_PATH'.  The next time `/etc/profile' is
-            sourced, it will set up an appropriate `LD_LIBRARY_PATH', though.
-          '';
-        };
-      };
-    };
-  };
-in
-
-###### implementation
 let
+
   cfg = config.services.avahi;
-  inherit (pkgs.lib) mkIf mkThenElse;
 
-  inherit (pkgs) avahi writeText lib;
+  inherit (pkgs) avahi;
 
-  avahiDaemonConf = with cfg; writeText "avahi-daemon.conf" ''
+  avahiDaemonConf = with cfg; pkgs.writeText "avahi-daemon.conf" ''
     [server]
     host-name=${hostName}
-    browse-domains=${lib.concatStringsSep ", " browseDomains}
+    browse-domains=${concatStringsSep ", " browseDomains}
     use-ipv4=${if ipv4 then "yes" else "no"}
     use-ipv6=${if ipv6 then "yes" else "no"}
 
@@ -91,69 +23,119 @@ let
     disable-publishing=${if publishing then "no" else "yes"}
   '';
 
-  user = {
-    name = "avahi";
-    uid = config.ids.uids.avahi;
-    description = "`avahi-daemon' privilege separation user";
-    home = "/var/empty";
-  };
+in
 
-  group = {
-    name = "avahi";
-    gid = config.ids.gids.avahi;
-  };
+{
 
-  job = {
-    name = "avahi-daemon";
+  ###### interface
 
-    job = ''
-      start on network-interfaces/started
-      stop on network-interfaces/stop
-      respawn
-      script
-        export PATH="${avahi}/bin:${avahi}/sbin:$PATH"
+  options = {
+  
+    services.avahi = {
+
+      enable = mkOption {
+        default = false;
+        description = ''
+          Whether to run the Avahi daemon, which allows Avahi clients
+          to use Avahi's service discovery facilities and also allows
+          the local machine to advertise its presence and services
+          (through the mDNS responder implemented by `avahi-daemon').
+        '';
+      };
 
-        # Make NSS modules visible so that `avahi_nss_support ()' can
-        # return a sensible value.
-        export LD_LIBRARY_PATH="${config.system.nssModules.path}"
+      hostName = mkOption {
+        default = config.networking.hostName;
+        description = ''Host name advertised on the LAN.'';
+      };
 
-        exec ${avahi}/sbin/avahi-daemon --daemonize -f "${avahiDaemonConf}"
-      end script
-    '';
-  };
-in
+      browseDomains = mkOption {
+        default = [ "0pointer.de" "zeroconf.org" ];
+        description = ''
+          List of non-local DNS domains to be browsed.
+        '';
+      };
 
-mkIf cfg.enable {
-  require = [
-    # ../upstart-jobs/default.nix # config.services.extraJobs
-    # ../system/? # system.nssModules
-    # ? # config.environment.etc
-    # ../system/user.nix # users.*
-    # ../upstart-jobs/udev.nix # services.udev.*
-    # ../upstart-jobs/dbus.nix # services.dbus.*
-    # ? # config.environment.extraPackages
-    options
-  ];
-
-  system = {
-    nssModules = pkgs.lib.optional cfg.nssmdns pkgs.nssmdns;
-  };
+      ipv4 = mkOption {
+        default = true;
+        description = ''Whether to use IPv4'';
+      };
 
-  environment = {
-    systemPackages = [avahi];
-  };
+      ipv6 = mkOption {
+        default = false;
+        description = ''Whether to use IPv6'';
+      };
 
-  users = {
-    extraUsers = [user];
-    extraGroups = [group];
-  };
+      wideArea = mkOption {
+        default = true;
+        description = ''Whether to enable wide-area service discovery.'';
+      };
 
-  services = {
-    extraJobs = [job];
+      publishing = mkOption {
+        default = true;
+        description = ''Whether to allow publishing.'';
+      };
 
-    dbus = {
-      enable = true;
-      packages = [avahi];
+      nssmdns = mkOption {
+        default = false;
+        description = ''
+          Whether to enable the mDNS NSS (Name Service Switch) plug-in.
+          Enabling it allows applications to resolve names in the `.local'
+          domain by transparently querying the Avahi daemon.
+
+          Warning: Currently, enabling this option breaks DNS lookups after
+          a `nixos-rebuild'.  This is because `/etc/nsswitch.conf' is
+          updated to use `nss-mdns' but `libnss_mdns' is not in
+          applications' `LD_LIBRARY_PATH'.  The next time `/etc/profile' is
+          sourced, it will set up an appropriate `LD_LIBRARY_PATH', though.
+        '';
+      };
+      
     };
+    
+  };
+  
+
+  ###### implementation
+
+  config = mkIf cfg.enable {
+
+    users.extraUsers = singleton
+      { name = "avahi";
+        uid = config.ids.uids.avahi;
+        description = "`avahi-daemon' privilege separation user";
+        home = "/var/empty";
+      };
+
+    users.extraGroups = singleton
+      { name = "avahi";
+        gid = config.ids.gids.avahi;
+      };
+
+    system.nssModules = optional cfg.nssmdns pkgs.nssmdns;
+
+    environment.systemPackages = [ avahi ];
+
+    jobAttrs.avahi_daemon =
+      { name = "avahi-daemon";
+
+        startOn = "network-interfaces/started";
+        stopOn = "network-interfaces/stop";
+
+        script =
+          ''
+            export PATH="${avahi}/bin:${avahi}/sbin:$PATH"
+
+            # Make NSS modules visible so that `avahi_nss_support ()' can
+            # return a sensible value.
+            export LD_LIBRARY_PATH="${config.system.nssModules.path}"
+
+            exec ${avahi}/sbin/avahi-daemon --daemonize -f "${avahiDaemonConf}"
+          '';
+      };
+
+    services.dbus.enable = true;
+    services.dbus.packages = [avahi];
+
   };
+
 }