- Move some system configuration to options:

* system.nssModules
  * system.modulesTree
  * system.sbin.modprobe
  * system.sbin.mount
  * nix.envVars

- Remove Arguments that can be accessed either by "config" or "pkgs".

- Use the new scheme for upstart-jobs/default.nix.
This is now a configuration file which is imported by system/options.nix.

- Jobs can now include upstart-job/default.nix:
  * upstrat-jobs/cron.nix
  * upstart-jobs/dhclient.nix

=> No Nixos file refers to upstart-jobs/default.nix except if one of its options is require to define an extra job. (e.g.: cron, dhclient)

svn path=/nixos/branches/fix-style/; revision=13327
This commit is contained in:
Nicolas Pierron 2008-11-18 18:00:09 +00:00
parent d7c321c64a
commit 892d12bccf
10 changed files with 227 additions and 121 deletions

View file

@ -42,13 +42,5 @@ in
manifests = system.config.installer.manifests; # exported here because nixos-rebuild uses it
upstartJobsCombined = system.upstartJobs;
# Make it easier to build individual Upstart jobs (e.g., "nix-build
# /etc/nixos/nixos -A upstartJobs.xserver").
upstartJobs = { recurseForDerivations = true; } //
builtins.listToAttrs (map (job:
{ name = if job ? jobName then job.jobName else job.name; value = job; }
) system.upstartJobs.jobs);
tests = system.config.tests;
}

View file

@ -51,7 +51,7 @@ where <replaceable>attr</replaceable> is an attribute in
<listitem><para>An attribute set containing the Upstart jobs. For
instance, the <varname>sshd</varname> Upstart job can be built by
doing <literal>nix-build /etc/nixos/nixos -A
upstartJobs.sshd</literal>.</para></listitem>
tests.upstartJobs.sshd</literal>.</para></listitem>
</varlistentry>
</variablelist>

View file

@ -1,4 +1,4 @@
{ config, pkgs, upstartJobs, systemPath, wrapperDir
{ config, pkgs, systemPath, wrapperDir
, defaultShell, extraEtc, nixEnvVars, modulesTree, nssModulesPath
}:
@ -73,11 +73,6 @@ import ../helpers/make-etc.nix {
target = "login.defs";
}
{ # The Upstart events defined above.
source = upstartJobs + "/etc/event.d";
target = "event.d";
}
{ # Configuration for passwd and friends (e.g., hash algorithm
# for /etc/passwd).
source = ./default/passwd;

View file

@ -332,6 +332,92 @@ in
};
system = {
# NSS modules. Hacky!
nssModules = mkOption {
internal = true;
default = [];
description = "
Search path for NSS (Name Service Switch) modules. This allows
several DNS resolution methods to be specified via
<filename>/etc/nsswitch.conf</filename>.
";
merge = pkgs.lib.mergeListOption;
apply = list:
let
list2 =
list
++ pkgs.lib.optional config.users.ldap.enable pkgs.nss_ldap
++ pkgs.lib.optional config.services.avahi.nssmdns pkgs.nssmdns;
in {
list = list2;
path = pkgs.lib.makeLibraryPath list2;
};
};
modulesTree = mkOption {
internal = true;
default = [];
description = "
Tree of kernel modules. This includes the kernel, plus modules
built outside of the kernel. Combine these into a single tree of
symlinks because modprobe only supports one directory.
";
merge = pkgs.lib.mergeListOption;
# Convert the list of path to only one path.
apply = list: pkgs.aggregateModules (
let
kernelPackages = config.boot.kernelPackages;
kernel = kernelPackages.kernel;
in
[ kernel ]
++ pkgs.lib.optional ((config.networking.enableIntel3945ABGFirmware || config.networking.enableIntel4965AGNFirmware) && !kernel.features ? iwlwifi) kernelPackages.iwlwifi
# !!! this should be declared by the xserver Upstart job.
++ pkgs.lib.optional (config.services.xserver.enable && config.services.xserver.videoDriver == "nvidia") kernelPackages.nvidiaDrivers
++ pkgs.lib.optional config.hardware.enableGo7007 kernelPackages.wis_go7007
++ config.boot.extraModulePackages
# should only keep this one, other have to be set by the option owners.
++ list
);
};
sbin = {
modprobe = mkOption {
# should be moved in module-init-tools
internal = true;
default = pkgs.substituteAll {
dir = "sbin";
src = ./modprobe;
isExecutable = true;
inherit (pkgs) module_init_tools;
inherit (config.system) modulesTree;
};
description = "
Path to the modprobe binary used by the system.
";
};
mount = mkOption {
internal = true;
default = pkgs.utillinux.passthru.function {
buildMountOnly = true;
mountHelpers = pkgs.buildEnv {
name = "mount-helpers";
paths = [
pkgs.ntfs3g
pkgs.mount_cifs
];
pathsToLink = "/sbin";
} + "/sbin";
};
description = "
Install a special version of mount to search mount tools in
unusual path.
";
};
};
};
# Hm, this sounds like a catch-all...
hardware = {
@ -594,24 +680,6 @@ in
services = {
extraJobs = mkOption {
default = [];
example = [
{ name = "test-job";
job = ''
description "nc"
start on started network-interfaces
respawn
env PATH=/var/run/current-system/sw/bin
exec sh -c "echo 'hello world' | ${pkgs.netcat}/bin/nc -l -p 9000"
'';
} ];
description = "
Additional Upstart jobs.
";
};
syslogd = {
@ -2659,6 +2727,36 @@ in
";
};
# Environment variables for running Nix.
envVars = mkOption {
internal = true;
default = "";
description = "
Define the environment variables used by nix to
";
merge = pkgs.lib.mergeStringOption;
# other option should be used to define the content instead of using
# the apply function.
apply = conf: ''
export NIX_CONF_DIR=/nix/etc/nix
# Enable the copy-from-other-stores substituter, which allows builds
# to be sped up by copying build results from remote Nix stores. To
# do this, mount the remote file system on a subdirectory of
# /var/run/nix/remote-stores.
export NIX_OTHER_STORES=/var/run/nix/remote-stores/*/nix
'' + # */
(if config.nix.distributedBuilds then
''
export NIX_BUILD_HOOK=${config.environment.nix}/libexec/nix/build-remote.pl
export NIX_REMOTE_SYSTEMS=/etc/nix.machines
export NIX_CURRENT_LOAD=/var/run/nix/current-load
''
else "") + conf;
};
};
@ -3020,6 +3118,9 @@ root ALL=(ALL) SETENV: ALL
};
require = [
# system
(import ../upstart-jobs/default.nix)
# newtworking
(import ../upstart-jobs/dhclient.nix)

View file

@ -36,19 +36,7 @@ rec {
kernel = kernelPackages.kernel;
# Tree of kernel modules. This includes the kernel, plus modules
# built outside of the kernel. We have to combine these into a
# single tree of symlinks because modprobe only supports one
# directory.
modulesTree = pkgs.aggregateModules (
[kernel]
++ pkgs.lib.optional ((config.networking.enableIntel3945ABGFirmware || config.networking.enableIntel4965AGNFirmware) && !kernel.features ? iwlwifi) kernelPackages.iwlwifi
# !!! this should be declared by the xserver Upstart job.
++ pkgs.lib.optional (config.services.xserver.enable && config.services.xserver.videoDriver == "nvidia") kernelPackages.nvidiaDrivers
++ pkgs.lib.optional config.hardware.enableGo7007 kernelPackages.wis_go7007
++ config.boot.extraModulePackages
);
modulesTree = config.system.modulesTree;
# The initial ramdisk.
@ -66,59 +54,24 @@ rec {
# NSS modules. Hacky!
nssModules =
pkgs.lib.optional config.users.ldap.enable pkgs.nss_ldap
++ pkgs.lib.optional config.services.avahi.nssmdns pkgs.nssmdns;
nssModules = config.system.nssModules.list;
nssModulesPath = pkgs.lib.concatStrings (pkgs.lib.intersperse ":"
(map (mod: mod + "/lib") nssModules));
nssModulesPath = config.system.nssModules.path;
# Wrapper around modprobe to set the path to the modules.
modprobe = pkgs.substituteAll {
dir = "sbin";
src = ./modprobe;
isExecutable = true;
inherit (pkgs) module_init_tools;
inherit modulesTree;
};
modprobe = config.system.sbin.modprobe;
# Environment variables for running Nix.
nixEnvVars =
''
export NIX_CONF_DIR=/nix/etc/nix
# Enable the copy-from-other-stores substituter, which allows builds
# to be sped up by copying build results from remote Nix stores. To
# do this, mount the remote file system on a subdirectory of
# /var/run/nix/remote-stores.
export NIX_OTHER_STORES=/var/run/nix/remote-stores/*/nix
'' + # */
(if config.nix.distributedBuilds then
''
export NIX_BUILD_HOOK=${nix}/libexec/nix/build-remote.pl
export NIX_REMOTE_SYSTEMS=/etc/nix.machines
export NIX_CURRENT_LOAD=/var/run/nix/current-load
''
else "");
nixEnvVars = config.nix.envVars;
# The services (Upstart) configuration for the system.
upstartJobs = import ../upstart-jobs/default.nix {
inherit config pkgs nix modprobe nssModulesPath nixEnvVars
optionDeclarations kernelPackages mount;
};
# The static parts of /etc.
etc = import ../etc/default.nix {
inherit config pkgs upstartJobs systemPath wrapperDir
inherit config pkgs systemPath wrapperDir
defaultShell nixEnvVars modulesTree nssModulesPath;
extraEtc =
(pkgs.lib.concatLists (map (job: job.extraEtc) upstartJobs.jobs))
++ config.environment.etc;
extraEtc = config.environment.etc;
};
@ -143,18 +96,7 @@ rec {
# A patched `mount' command that looks in a directory in the Nix
# store instead of in /sbin for mount helpers (like mount.ntfs-3g or
# mount.cifs).
mount = import "${nixpkgsPath}/pkgs/os-specific/linux/util-linux" {
inherit (pkgs) fetchurl stdenv;
buildMountOnly = true;
mountHelpers = pkgs.buildEnv {
name = "mount-helpers";
paths = [
pkgs.ntfs3g
pkgs.mount_cifs
];
pathsToLink = "/sbin";
} + "/sbin";
};
mount = config.system.sbin.mount;
# The packages you want in the boot environment.
@ -220,7 +162,6 @@ rec {
++ pkgs.lib.optional config.services.bitlbee.enable pkgs.bitlbee
++ pkgs.lib.optional config.services.avahi.enable pkgs.avahi
++ pkgs.lib.optional config.networking.defaultMailServer.directDelivery pkgs.ssmtp
++ pkgs.lib.concatLists (map (job: job.extraPath) upstartJobs.jobs)
++ config.environment.extraPackages
++ pkgs.lib.optional config.fonts.enableFontDir fontDir
++ pkgs.lib.optional config.hardware.enableGo7007 kernelPackages.wis_go7007
@ -248,7 +189,7 @@ rec {
};
usersGroups = import ./users-groups.nix { inherit pkgs config upstartJobs defaultShell; };
usersGroups = import ./users-groups.nix { inherit pkgs config defaultShell; };
defaultShell = "/var/run/current-system/sw/bin/bash";

View file

@ -1,4 +1,4 @@
{pkgs, config, upstartJobs, defaultShell}:
{pkgs, config, defaultShell}:
let ids = import ./ids.nix; in
@ -7,8 +7,6 @@ rec {
# User accounts to be created/updated by NixOS.
users =
let
jobUsers = pkgs.lib.concatLists (map (job: job.users) upstartJobs.jobs);
defaultUsers =
[
{ name = "root";
@ -46,14 +44,12 @@ rec {
}:
{ inherit name description uid group extraGroups home shell createHome; };
in map addAttrs (defaultUsers ++ jobUsers ++ nixBuildUsers ++ config.users.extraUsers);
in map addAttrs (defaultUsers ++ nixBuildUsers ++ config.users.extraUsers);
# Groups to be created/updated by NixOS.
groups =
let
jobGroups = pkgs.lib.concatLists (map (job: job.groups) upstartJobs.jobs);
defaultGroups =
[
{ name = "root";
@ -95,7 +91,7 @@ rec {
{ name, gid ? "" }:
{ inherit name gid; };
in map addAttrs (defaultGroups ++ jobGroups ++ config.users.extraGroups);
in map addAttrs (defaultGroups ++ config.users.extraGroups);
# Awful hackery necessary to pass the users/groups to the activation script.

View file

@ -10,7 +10,7 @@ fi
for i in $*; do
echo "building job $i..."
nix-build /etc/nixos/nixos -A "upstartJobs.$i" -o $tmpDir/.result
nix-build /etc/nixos/nixos -A "tests.upstartJobs.$i" -o $tmpDir/.result
ln -sfn $(readlink -f $tmpDir/.result)/etc/event.d/* /tmp/event.d/
done

View file

@ -49,7 +49,7 @@ in
{
require = [
# (import ../upstart-jobs/default.nix) # config.services.extraJobs
(import ../upstart-jobs/default.nix) # config.services.extraJobs
# (import ?) # config.time.timeZone
# (import ?) # config.environment.etc
# (import ?) # config.environment.extraPackages

View file

@ -1,6 +1,54 @@
{config, pkgs, nix, modprobe, nssModulesPath, nixEnvVars, optionDeclarations, kernelPackages, mount}:
{config, pkgs}:
let
###### interface
let
inherit (pkgs.lib) mkOption;
options = {
services = {
extraJobs = mkOption {
default = [];
example = [
{ name = "test-job";
job = ''
description "nc"
start on started network-interfaces
respawn
env PATH=/var/run/current-system/sw/bin
exec sh -c "echo 'hello world' | ${pkgs.netcat}/bin/nc -l -p 9000"
'';
} ];
# should have some checks to everify the syntax
merge = pkgs.lib.mergeListOption;
description = "
Additional Upstart jobs.
";
};
};
tests = {
upstartJobs = mkOption {
internal = true;
default = {};
description = "
Make it easier to build individual Upstart jobs. (e.g.,
<command>nix-build /etc/nixos/nixos -A
tests.upstartJobs.xserver</command>).
";
};
};
};
in
###### implementation
let
# should be moved to the corresponding jobs.
nix = config.environment.nix;
nixEnvVars = config.nix.envVars;
kernelPackages = config.boot.kernelPackages;
nssModulesPath = config.system.nssModules.path;
modprobe = config.system.sbin.modprobe;
mount = config.system.sbin.mount;
makeJob = import ../upstart-jobs/make-job.nix {
inherit (pkgs) runCommand;
@ -58,9 +106,7 @@ let
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 name}"
else abort "unkown option ${errorWhere name}";
checkConfig = (pkgs.lib.getAttr ["environment" "checkConfigurationOptions"]
optionDeclarations.environment.checkConfigurationOptions.default
config);
checkConfig = config.environment.checkConfigurationOptions;
in # TODO: pass path to checker so it can show full path in the abort case
pkgs.checker ( (jobFunc (args configV)).jobs )
checkConfig
@ -464,8 +510,43 @@ let
# For the built-in logd job.
++ [(makeJob { jobDrv = pkgs.upstart; })];
command = import ../upstart-jobs/gather.nix {
inherit (pkgs) runCommand;
inherit jobs;
};
in import ../upstart-jobs/gather.nix {
inherit (pkgs) runCommand;
inherit jobs;
}
in
{
require = [
options
];
environment = {
etc = [{ # The Upstart events defined above.
source = command + "/etc/event.d";
target = "event.d";
}]
++ pkgs.lib.concatLists (map (job: job.extraEtc) jobs);
extraPackages =
pkgs.lib.concatLists (map (job: job.extraPath) jobs);
};
users = {
extraUsers =
pkgs.lib.concatLists (map (job: job.users) jobs);
extraGroups =
pkgs.lib.concatLists (map (job: job.groups) jobs);
};
tests = {
# see test/test-upstart-job.sh
upstartJobs = { recurseForDerivations = true; } //
builtins.listToAttrs (map (job:
{ name = if job ? jobName then job.jobName else job.name; value = job; }
) jobs);
};
}

View file

@ -56,7 +56,7 @@ in
{
require = [
# (import ../upstart-jobs/default.nix)
(import ../upstart-jobs/default.nix)
options
];