anchor.diff:        }
       '';
     
  +  events = [powerEvent lidEvent acEvent];
  +  
     # Called when the power button is pressed.
     powerEvent =
       { name = "power-button";
  
positive.code:       action =
          ''
            #! ${pkgs.bash}/bin/sh
  
            # Suspend to RAM if the lid is closed.  (We also get this event
            # when the lid just opened, in which case we obviously don't
            # want to suspend again.) 
            if grep -q closed /proc/acpi/button/lid/LID/state; then
                sync
                echo mem > /sys/power/state
            fi
          '';
      };
    
  
negative.code:       action = 
          ''
            #! ${pkgs.bash}/bin/sh
          '';
      };
  
  in
  
  {
  
    ###### interface
  
    options = {
    
      powerManagement = {
  
        enable = mkOption {
          default = false;
          description = "Whether to enable power management (ACPI daemon)";
        };
        
      };
      
    };
    
  
    ###### implementation
  
    config = mkIf config.powerManagement.enable {
  
      jobs = singleton
        { name = "acpid";
          description = "ACPI daemon";
  
          startOn = "udev";
          stopOn = "shutdown";
  
          exec = "${pkgs.acpid}/sbin/acpid --foreground --confdir ${acpiConfDir}";
        };
        
    };
    
  }
  