From 40d9d628790f0e1fee9666dd4e22cd8420f558cd Mon Sep 17 00:00:00 2001 From: Marc Weber Date: Sun, 16 Mar 2008 01:05:40 +0000 Subject: [PATCH] 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 --- system/options.nix | 15 ++++++++++ system/system.nix | 2 +- upstart-jobs/default.nix | 64 ++++++++++++++++++++++++++++++++++++++-- upstart-jobs/httpd.nix | 2 +- 4 files changed, 78 insertions(+), 5 deletions(-) diff --git a/system/options.nix b/system/options.nix index 098f28848c8c..409cbba39061 100644 --- a/system/options.nix +++ b/system/options.nix @@ -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 = " diff --git a/system/system.nix b/system/system.nix index b1a2a91d3f1a..d6ea63aee571 100644 --- a/system/system.nix +++ b/system/system.nix @@ -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; }; diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix index 1cb509030051..7c855c9485fb 100644 --- a/upstart-jobs/default.nix +++ b/upstart-jobs/default.nix @@ -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 diff --git a/upstart-jobs/httpd.nix b/upstart-jobs/httpd.nix index 58e993a556c4..45ac26610e6a 100644 --- a/upstart-jobs/httpd.nix +++ b/upstart-jobs/httpd.nix @@ -32,7 +32,7 @@ let user group adminAddr logDir stateDir applicationMappings; noUserDir = !cfg.enableUserDir; - extraDirectories = extraConfig + cfg.extraConfig; + extraDirectories = extraConfig + "\n" + cfg.extraConfig; subServices =