added mkOption extraConfig for httpd apache service

( added \n in config concatenation as well )
added serviceProposal, examples see upstart-jobs/newProposal/*.nix
  enhancement: everything belonging to one job is within the same file 
  (was: upstart-jobs/default.nix, options.nix and the job file)
  drawback: options won't be included within the manual 
            (can be fixed see comments in options.nix)
  comment: looking at the funtion newProposalJobs maybe it's overkill? 
           Hope it pays off if we start having dozens of small different services..


svn path=/nixos/trunk/; revision=11141
This commit is contained in:
Marc Weber 2008-03-16 01:05:40 +00:00
parent cf16b3acfe
commit 40d9d62879
4 changed files with 78 additions and 5 deletions

View file

@ -543,6 +543,14 @@
";
};
servicesProposal = {
# see upstart-jobs/default.nix
# the option declarations can be found in the upstart-jobs/newProposal/*.nix files
# one way to include the declarations here is adding kind of glob "*.nix"
# file function to builtins to get all jobs
# then the checking in upstart-jobs/default.nix can be removed again (together with passing arg optionDeclarations)
};
services = {
@ -1359,6 +1367,13 @@
";
};
extraConfig = mkOption {
default = "";
description = "
These configuration lines will be passed verbatim to the apache config
";
};
logPerVirtualHost = mkOption {
default = false;
description = "

View file

@ -170,7 +170,7 @@ rec {
# The services (Upstart) configuration for the system.
upstartJobs = import ../upstart-jobs/default.nix {
inherit config pkgs nix modprobe nssModulesPath nixEnvVars;
inherit config pkgs nix modprobe nssModulesPath nixEnvVars optionDeclarations;
};

View file

@ -1,4 +1,4 @@
{config, pkgs, nix, modprobe, nssModulesPath, nixEnvVars}:
{config, pkgs, nix, modprobe, nssModulesPath, nixEnvVars, optionDeclarations}:
let
@ -13,8 +13,66 @@ let
++ config.boot.extraTTYs
++ [config.services.syslogd.tty];
# looks for a job file foreach attr name found in services from config
# passes { thisConfig, config, pkgs }
# a job must return { options = {}; job =; }
# options is the same format as options.nix, but only contains documentation for this job
# TODO check validation
newProposalJobs =
__trace (pkgs.lib.whatis config) (
let
inherit (pkgs.lib) getAttr;
inherit (builtins) attrNames pathExists map;
services = pkgs.lib.traceWhatis ( getAttr [ "servicesProposal" ] {} config);
nameToJobs = name : (
__trace ("name : ${name}") (
let p = ./newProposal + "/${name}.nix";
p2 = ./newProposal + "/${name}/default.nix";
thisConfig = getAttr [ name ] {} services;
path = [name];
args = confgiV : {
inherit config pkgs thisConfig path;
lib = pkgs.lib;
upstartHelpers = { # some useful functions
inherit configV; # the first time a error function is passed to get the option list
# the second time a function is passed getting the option for you automatically,
# either returning the default option or the user supplied value (the function apply is applied when given)
# maybe this is complicated, but easy to use (IMHO)
mkOption = pkgs.lib.mkOption; # the same function used in options.nix
autoGeneratedEtcFile = { name, commentChar ? "#", content } :
{ source = pkgs.writeText name
("${commentChar} nixos autogenerated etc file based on /etc/nixos/configuration.nix\n" + content);
target = name;
};
};
};
jobFunc = if pathExists p
then import p
else if pathExists p2 then import p2
else abort "service ${name} requested but there is no ${p}.nix or ${p}/default.nix file!";
options = (jobFunc (args (abort "you can't use configV within options!"))).options;
errorWhere = "${name} of service ${builtins.toString path}";
configV = name : if (__hasAttr name options ) then
let opt = (__getAttr name options ); # this config option description
in if (__hasAttr name thisConfig )
then let v = (__getAttr name thisConfig); in if opt ? apply then opt.apply v else v
else if opt ? default then opt.default else abort "you need to specify the configuration option ${errorWhere}"
else abort "unkown option ${errorWhere}";
checkConfig = (pkgs.lib.getAttr ["environment" "checkConfigurationOptions"]
optionDeclarations.environment.checkConfigurationOptions.default
config);
in # TODO: pass path to checker so it can show full path in the abort case
pkgs.checker ( (jobFunc (args configV)).jobs )
checkConfig
options
thisConfig
));
in pkgs.lib.concatLists ( map nameToJobs (attrNames services)));
jobs = map makeJob [
jobs = map makeJob
( newProposalJobs ++
[
# Syslogd.
(import ../upstart-jobs/syslogd.nix {
inherit (pkgs) sysklogd;
@ -107,7 +165,7 @@ let
# Ctrl-alt-delete action.
(import ../upstart-jobs/ctrl-alt-delete.nix)
]
])
# DHCP client.
++ optional config.networking.useDHCP

View file

@ -32,7 +32,7 @@ let
user group adminAddr logDir stateDir
applicationMappings;
noUserDir = !cfg.enableUserDir;
extraDirectories = extraConfig + cfg.extraConfig;
extraDirectories = extraConfig + "\n" + cfg.extraConfig;
subServices =