2009-01-02 17:06:52 +01:00
|
|
|
|
# produce a script to generate /etc
|
|
|
|
|
{config, pkgs, ...}:
|
2006-12-11 16:32:10 +01:00
|
|
|
|
|
2009-01-02 17:06:52 +01:00
|
|
|
|
###### interface
|
|
|
|
|
let
|
|
|
|
|
inherit (pkgs.lib) mkOption;
|
|
|
|
|
|
|
|
|
|
option = {
|
|
|
|
|
environment = {
|
|
|
|
|
etc = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
example = [
|
|
|
|
|
{ source = "/nix/store/.../etc/dir/file.conf.example";
|
|
|
|
|
target = "dir/file.conf";
|
|
|
|
|
mode = "0440";
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
description = "
|
|
|
|
|
List of files that have to be linked in /etc.
|
|
|
|
|
";
|
|
|
|
|
};
|
2009-04-12 00:12:02 +02:00
|
|
|
|
|
|
|
|
|
# !!! This should be moved outside of /etc/default.nix.
|
|
|
|
|
shellInit = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
example = ''export PATH=/godi/bin/:$PATH'';
|
|
|
|
|
description = "
|
|
|
|
|
Script used to initialized user shell environments.
|
|
|
|
|
";
|
|
|
|
|
merge = pkgs.lib.mergeStringOption;
|
|
|
|
|
};
|
2009-01-02 17:06:52 +01:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
let
|
2009-04-12 00:12:02 +02:00
|
|
|
|
shellInit = config.environment.shellInit;
|
2008-11-23 02:29:20 +01:00
|
|
|
|
nixEnvVars = config.nix.envVars;
|
|
|
|
|
modulesTree = config.system.modulesTree;
|
|
|
|
|
nssModulesPath = config.system.nssModules.path;
|
2009-01-02 17:06:52 +01:00
|
|
|
|
wrapperDir = config.system.wrapperDir;
|
|
|
|
|
systemPath = config.system.path;
|
2009-01-02 20:41:39 +01:00
|
|
|
|
binsh = config.system.build.binsh;
|
2007-06-10 22:02:07 +02:00
|
|
|
|
|
2007-11-09 19:49:45 +01:00
|
|
|
|
optional = pkgs.lib.optional;
|
2007-01-16 17:09:43 +01:00
|
|
|
|
|
2007-06-10 22:02:07 +02:00
|
|
|
|
|
|
|
|
|
# !!! ugh, these files shouldn't be created here.
|
2008-01-04 18:05:48 +01:00
|
|
|
|
pamConsoleHandlers = pkgs.writeText "console.handlers" ''
|
|
|
|
|
console consoledevs /dev/tty[0-9][0-9]* :[0-9]\.[0-9] :[0-9]
|
|
|
|
|
${pkgs.pam_console}/sbin/pam_console_apply lock logfail wait -t tty -s -c ${pamConsolePerms}
|
|
|
|
|
${pkgs.pam_console}/sbin/pam_console_apply unlock logfail wait -r -t tty -s -c ${pamConsolePerms}
|
|
|
|
|
'';
|
2007-06-10 22:02:07 +02:00
|
|
|
|
|
|
|
|
|
pamConsolePerms = ./security/console.perms;
|
|
|
|
|
|
2009-01-02 17:06:52 +01:00
|
|
|
|
# These should be moved into the corresponding configuration files.
|
2006-12-11 16:32:10 +01:00
|
|
|
|
configFiles = [
|
|
|
|
|
{ # TCP/UDP port assignments.
|
|
|
|
|
source = pkgs.iana_etc + "/etc/services";
|
|
|
|
|
target = "services";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{ # IP protocol numbers.
|
|
|
|
|
source = pkgs.iana_etc + "/etc/protocols";
|
|
|
|
|
target = "protocols";
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-17 13:33:21 +01:00
|
|
|
|
{ # RPC program numbers.
|
|
|
|
|
source = pkgs.glibc + "/etc/rpc";
|
|
|
|
|
target = "rpc";
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-11 16:32:10 +01:00
|
|
|
|
{ # Hostname-to-IP mappings.
|
2008-01-04 18:05:48 +01:00
|
|
|
|
source = pkgs.substituteAll {
|
|
|
|
|
src = ./hosts;
|
|
|
|
|
extraHosts = config.networking.extraHosts;
|
|
|
|
|
};
|
2006-12-11 16:32:10 +01:00
|
|
|
|
target = "hosts";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{ # Friendly greeting on the virtual consoles.
|
2008-01-04 18:05:48 +01:00
|
|
|
|
source = pkgs.writeText "issue" ''
|
|
|
|
|
|
|
|
|
|
[1;32m${config.services.mingetty.greetingLine}[0m
|
|
|
|
|
${config.services.mingetty.helpLine}
|
|
|
|
|
|
|
|
|
|
'';
|
2006-12-11 16:32:10 +01:00
|
|
|
|
target = "issue";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{ # Configuration for pwdutils (login, passwd, useradd, etc.).
|
|
|
|
|
# You cannot login without it!
|
2007-03-30 14:59:43 +02:00
|
|
|
|
source = ./login.defs;
|
2006-12-11 16:32:10 +01:00
|
|
|
|
target = "login.defs";
|
2009-01-02 17:06:52 +01:00
|
|
|
|
}
|
2006-12-11 16:32:10 +01:00
|
|
|
|
|
|
|
|
|
{ # Configuration for passwd and friends (e.g., hash algorithm
|
|
|
|
|
# for /etc/passwd).
|
2007-03-30 14:59:43 +02:00
|
|
|
|
source = ./default/passwd;
|
2006-12-11 16:32:10 +01:00
|
|
|
|
target = "default/passwd";
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-20 14:30:14 +01:00
|
|
|
|
{ # Configuration for useradd.
|
|
|
|
|
source = pkgs.substituteAll {
|
2007-03-30 14:59:43 +02:00
|
|
|
|
src = ./default/useradd;
|
2009-01-02 17:06:52 +01:00
|
|
|
|
defaultShell = config.system.shell;
|
2007-03-20 14:30:14 +01:00
|
|
|
|
};
|
|
|
|
|
target = "default/useradd";
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-22 18:28:25 +01:00
|
|
|
|
{ # Dhclient hooks for emitting ip-up/ip-down events.
|
|
|
|
|
source = pkgs.substituteAll {
|
2007-03-30 14:59:43 +02:00
|
|
|
|
src = ./dhclient-exit-hooks;
|
2007-01-23 11:22:00 +01:00
|
|
|
|
inherit (pkgs) upstart glibc;
|
2006-12-22 18:28:25 +01:00
|
|
|
|
};
|
|
|
|
|
target = "dhclient-exit-hooks";
|
|
|
|
|
}
|
2007-01-15 15:43:56 +01:00
|
|
|
|
|
2008-03-12 11:18:11 +01:00
|
|
|
|
{ # Script executed when the shell starts as a non-login shell (system-wide version).
|
2007-01-15 15:43:56 +01:00
|
|
|
|
source = pkgs.substituteAll {
|
2008-07-16 18:01:09 +02:00
|
|
|
|
src = ./bashrc.sh;
|
2008-03-17 14:58:57 +01:00
|
|
|
|
inherit systemPath wrapperDir modulesTree nssModulesPath;
|
2008-01-06 19:45:13 +01:00
|
|
|
|
inherit (pkgs) glibc;
|
2007-11-09 19:49:45 +01:00
|
|
|
|
timeZone = config.time.timeZone;
|
|
|
|
|
defaultLocale = config.i18n.defaultLocale;
|
2009-04-12 00:12:02 +02:00
|
|
|
|
inherit nixEnvVars shellInit;
|
2007-01-15 15:43:56 +01:00
|
|
|
|
};
|
2008-07-16 18:01:09 +02:00
|
|
|
|
target = "bashrc";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{ # Script executed when the shell starts as a login shell.
|
|
|
|
|
source = ./profile.sh;
|
2007-01-15 15:43:56 +01:00
|
|
|
|
target = "profile";
|
|
|
|
|
}
|
2007-01-16 17:09:43 +01:00
|
|
|
|
|
2007-05-02 11:55:35 +02:00
|
|
|
|
{ # Configuration for readline in bash.
|
|
|
|
|
source = ./inputrc;
|
|
|
|
|
target = "inputrc";
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-12 11:18:11 +01:00
|
|
|
|
{ # Script executed when the shell starts as a non-login shell (user version).
|
|
|
|
|
source = ./skel/bashrc;
|
|
|
|
|
target = "skel/.bashrc";
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-16 14:59:03 +01:00
|
|
|
|
{ # SSH configuration. Slight duplication of the sshd_config
|
|
|
|
|
# generation in the sshd service.
|
|
|
|
|
source = pkgs.writeText "ssh_config" ''
|
|
|
|
|
${if config.services.sshd.forwardX11 then ''
|
|
|
|
|
ForwardX11 yes
|
|
|
|
|
XAuthLocation ${pkgs.xorg.xauth}/bin/xauth
|
|
|
|
|
'' else ''
|
|
|
|
|
ForwardX11 no
|
|
|
|
|
''}
|
|
|
|
|
'';
|
|
|
|
|
target = "ssh/ssh_config";
|
|
|
|
|
}
|
2006-12-11 16:32:10 +01:00
|
|
|
|
]
|
|
|
|
|
|
2007-11-08 19:15:12 +01:00
|
|
|
|
# Configuration for ssmtp.
|
2007-11-09 19:49:45 +01:00
|
|
|
|
++ optional config.networking.defaultMailServer.directDelivery {
|
2008-01-04 18:05:48 +01:00
|
|
|
|
source = let cfg = config.networking.defaultMailServer; in pkgs.writeText "ssmtp.conf" ''
|
2008-04-24 14:36:50 +02:00
|
|
|
|
MailHub=${cfg.hostName}
|
|
|
|
|
FromLineOverride=YES
|
2008-01-04 18:05:48 +01:00
|
|
|
|
${if cfg.domain != "" then "rewriteDomain=${cfg.domain}" else ""}
|
|
|
|
|
UseTLS=${if cfg.useTLS then "YES" else "NO"}
|
|
|
|
|
UseSTARTTLS=${if cfg.useSTARTTLS then "YES" else "NO"}
|
|
|
|
|
#Debug=YES
|
|
|
|
|
'';
|
2007-11-08 19:15:12 +01:00
|
|
|
|
target = "ssmtp/ssmtp.conf";
|
2007-11-09 19:49:45 +01:00
|
|
|
|
}
|
2007-01-22 17:42:29 +01:00
|
|
|
|
|
2006-12-11 16:32:10 +01:00
|
|
|
|
# A bunch of PAM configuration files for various programs.
|
|
|
|
|
++ (map
|
|
|
|
|
(program:
|
2007-11-09 19:49:45 +01:00
|
|
|
|
let isLDAPEnabled = config.users.ldap.enable; in
|
2006-12-11 16:32:10 +01:00
|
|
|
|
{ source = pkgs.substituteAll {
|
2007-03-30 14:59:43 +02:00
|
|
|
|
src = ./pam.d + ("/" + program);
|
2007-06-10 22:02:07 +02:00
|
|
|
|
inherit (pkgs) pam_unix2 pam_console;
|
2007-01-16 17:09:43 +01:00
|
|
|
|
pam_ldap =
|
2007-06-10 22:02:07 +02:00
|
|
|
|
if isLDAPEnabled
|
2007-01-16 17:09:43 +01:00
|
|
|
|
then pkgs.pam_ldap
|
|
|
|
|
else "/no-such-path";
|
2007-01-16 23:25:28 +01:00
|
|
|
|
inherit (pkgs.xorg) xauth;
|
2008-07-16 18:01:09 +02:00
|
|
|
|
inherit pamConsoleHandlers;
|
2007-06-10 22:02:07 +02:00
|
|
|
|
isLDAPEnabled = if isLDAPEnabled then "" else "#";
|
2009-04-21 18:30:32 +02:00
|
|
|
|
syncSambaPasswords = if config.services.samba.syncPasswordsByPam
|
|
|
|
|
then "password optional ${pkgs.samba}/lib/security/pam_smbpass.so nullok use_authtok try_first_pass"
|
|
|
|
|
else "# change samba configuration options to make passwd sync the samba auth database as well here..";
|
2006-12-11 16:32:10 +01:00
|
|
|
|
};
|
|
|
|
|
target = "pam.d/" + program;
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
[
|
|
|
|
|
"login"
|
2007-01-11 16:32:48 +01:00
|
|
|
|
"su"
|
2006-12-16 22:48:12 +01:00
|
|
|
|
"other"
|
2006-12-11 16:32:10 +01:00
|
|
|
|
"passwd"
|
2006-12-16 22:48:12 +01:00
|
|
|
|
"shadow"
|
|
|
|
|
"sshd"
|
2008-03-06 15:38:17 +01:00
|
|
|
|
"lshd"
|
2006-12-11 16:32:10 +01:00
|
|
|
|
"useradd"
|
2007-02-26 22:18:13 +01:00
|
|
|
|
"chsh"
|
2008-03-06 14:52:10 +01:00
|
|
|
|
"xlock"
|
2009-03-29 23:43:40 +02:00
|
|
|
|
"samba"
|
2008-11-07 12:51:17 +01:00
|
|
|
|
"cups"
|
2009-02-28 21:01:56 +01:00
|
|
|
|
"ftp"
|
2009-04-13 11:35:03 +02:00
|
|
|
|
"ejabberd"
|
2007-01-30 16:03:43 +01:00
|
|
|
|
"common"
|
2007-06-10 22:02:07 +02:00
|
|
|
|
"common-console" # shared stuff for interactive local sessions
|
2006-12-11 16:32:10 +01:00
|
|
|
|
]
|
2007-03-30 14:55:09 +02:00
|
|
|
|
)
|
|
|
|
|
|
2007-11-15 18:16:16 +01:00
|
|
|
|
# List of machines for distributed Nix builds in the format expected
|
|
|
|
|
# by build-remote.pl.
|
|
|
|
|
++ optional config.nix.distributedBuilds {
|
|
|
|
|
source = pkgs.writeText "nix.machines"
|
|
|
|
|
(pkgs.lib.concatStrings (map (machine:
|
|
|
|
|
"${machine.sshUser}@${machine.hostName} ${machine.system} ${machine.sshKey} ${toString machine.maxJobs}\n"
|
|
|
|
|
) config.nix.buildMachines));
|
|
|
|
|
target = "nix.machines";
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-02 17:06:52 +01:00
|
|
|
|
;
|
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
let
|
2009-05-20 01:51:13 +02:00
|
|
|
|
inherit (pkgs.stringsWithDeps) noDepEntry fullDepEntry packEntry;
|
2009-01-02 17:06:52 +01:00
|
|
|
|
|
|
|
|
|
activateLib = config.system.activationScripts.lib;
|
|
|
|
|
|
|
|
|
|
copyScript = {source, target, mode ? "644", own ? "root.root"}:
|
|
|
|
|
assert target != "nixos"; ''
|
|
|
|
|
source="${source}"
|
|
|
|
|
target="/etc/${target}"
|
|
|
|
|
mkdir -p $(dirname "$target")
|
|
|
|
|
test -e "$target" && rm -f "$target"
|
|
|
|
|
cp "$source" "$target"
|
|
|
|
|
chown ${own} "$target"
|
|
|
|
|
chmod ${mode} "$target"
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
makeEtc = import ../helpers/make-etc.nix {
|
|
|
|
|
inherit (pkgs) stdenv;
|
|
|
|
|
configFiles = configFiles ++ config.environment.etc;
|
|
|
|
|
};
|
|
|
|
|
in
|
2008-06-12 01:06:53 +02:00
|
|
|
|
|
2009-01-02 17:06:52 +01:00
|
|
|
|
{
|
|
|
|
|
require = [
|
|
|
|
|
option
|
|
|
|
|
|
|
|
|
|
# config.system.build
|
2009-05-20 01:14:45 +02:00
|
|
|
|
../system/system-options.nix
|
2009-01-02 17:06:52 +01:00
|
|
|
|
|
|
|
|
|
# config.system.activationScripts
|
2009-05-20 01:14:45 +02:00
|
|
|
|
../system/activate-configuration.nix
|
2009-01-02 17:06:52 +01:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
system = {
|
|
|
|
|
build = {
|
|
|
|
|
etc = makeEtc;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
activationScripts = {
|
2009-05-20 01:51:13 +02:00
|
|
|
|
etc = fullDepEntry ''
|
2009-01-02 17:06:52 +01:00
|
|
|
|
# Set up the statically computed bits of /etc.
|
|
|
|
|
staticEtc=/etc/static
|
|
|
|
|
rm -f $staticEtc
|
|
|
|
|
ln -s ${makeEtc}/etc $staticEtc
|
|
|
|
|
for i in $(cd $staticEtc && find * -type l); do
|
|
|
|
|
mkdir -p /etc/$(dirname $i)
|
|
|
|
|
rm -f /etc/$i
|
|
|
|
|
if test -e "$staticEtc/$i.mode"; then
|
|
|
|
|
# Create a regular file in /etc.
|
|
|
|
|
cp $staticEtc/$i /etc/$i
|
|
|
|
|
chown 0.0 /etc/$i
|
|
|
|
|
chmod "$(cat "$staticEtc/$i.mode")" /etc/$i
|
|
|
|
|
else
|
|
|
|
|
# Create a symlink in /etc.
|
|
|
|
|
ln -s $staticEtc/$i /etc/$i
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Remove dangling symlinks that point to /etc/static. These are
|
|
|
|
|
# configuration files that existed in a previous configuration but not
|
|
|
|
|
# in the current one. For efficiency, don't look under /etc/nixos
|
|
|
|
|
# (where all the NixOS sources live).
|
|
|
|
|
for i in $(find /etc/ \( -path /etc/nixos -prune \) -o -type l); do
|
|
|
|
|
target=$(readlink "$i")
|
|
|
|
|
if test "''${target:0:''${#staticEtc}}" = "$staticEtc" -a ! -e "$i"; then
|
|
|
|
|
rm -f "$i"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
'' [
|
|
|
|
|
activateLib.systemConfig
|
|
|
|
|
activateLib.defaultPath # path to cp, chmod, chown
|
|
|
|
|
activateLib.stdio
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
};
|
2007-02-26 22:18:13 +01:00
|
|
|
|
}
|