2009-01-02 16:06:52 +00:00
|
|
|
# produce a script to generate /etc
|
|
|
|
{config, pkgs, ...}:
|
2006-12-11 15:32:10 +00:00
|
|
|
|
2009-01-02 16:06:52 +00: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-11 22:12:02 +00: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 16:06:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
let
|
2007-11-09 18:49:45 +00:00
|
|
|
optional = pkgs.lib.optional;
|
2007-01-16 16:09:43 +00:00
|
|
|
|
2007-06-10 20:02:07 +00:00
|
|
|
|
|
|
|
# !!! ugh, these files shouldn't be created here.
|
2008-01-04 17:05:48 +00: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 20:02:07 +00:00
|
|
|
|
|
|
|
pamConsolePerms = ./security/console.perms;
|
|
|
|
|
2009-05-28 12:43:54 +00:00
|
|
|
configFiles =
|
2006-12-11 15:32:10 +00:00
|
|
|
|
|
|
|
# A bunch of PAM configuration files for various programs.
|
2009-05-28 12:43:54 +00:00
|
|
|
(map
|
2006-12-11 15:32:10 +00:00
|
|
|
(program:
|
2007-11-09 18:49:45 +00:00
|
|
|
let isLDAPEnabled = config.users.ldap.enable; in
|
2006-12-11 15:32:10 +00:00
|
|
|
{ source = pkgs.substituteAll {
|
2007-03-30 12:59:43 +00:00
|
|
|
src = ./pam.d + ("/" + program);
|
2007-06-10 20:02:07 +00:00
|
|
|
inherit (pkgs) pam_unix2 pam_console;
|
2007-01-16 16:09:43 +00:00
|
|
|
pam_ldap =
|
2007-06-10 20:02:07 +00:00
|
|
|
if isLDAPEnabled
|
2007-01-16 16:09:43 +00:00
|
|
|
then pkgs.pam_ldap
|
|
|
|
else "/no-such-path";
|
2007-01-16 22:25:28 +00:00
|
|
|
inherit (pkgs.xorg) xauth;
|
2008-07-16 16:01:09 +00:00
|
|
|
inherit pamConsoleHandlers;
|
2007-06-10 20:02:07 +00:00
|
|
|
isLDAPEnabled = if isLDAPEnabled then "" else "#";
|
2009-04-21 16:30:32 +00: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 15:32:10 +00:00
|
|
|
};
|
|
|
|
target = "pam.d/" + program;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
[
|
|
|
|
"login"
|
2007-01-11 15:32:48 +00:00
|
|
|
"su"
|
2006-12-16 21:48:12 +00:00
|
|
|
"other"
|
2006-12-11 15:32:10 +00:00
|
|
|
"passwd"
|
2006-12-16 21:48:12 +00:00
|
|
|
"shadow"
|
|
|
|
"sshd"
|
2008-03-06 14:38:17 +00:00
|
|
|
"lshd"
|
2006-12-11 15:32:10 +00:00
|
|
|
"useradd"
|
2007-02-26 21:18:13 +00:00
|
|
|
"chsh"
|
2008-03-06 13:52:10 +00:00
|
|
|
"xlock"
|
2009-03-29 21:43:40 +00:00
|
|
|
"samba"
|
2008-11-07 11:51:17 +00:00
|
|
|
"cups"
|
2009-02-28 20:01:56 +00:00
|
|
|
"ftp"
|
2009-04-13 09:35:03 +00:00
|
|
|
"ejabberd"
|
2007-01-30 15:03:43 +00:00
|
|
|
"common"
|
2007-06-10 20:02:07 +00:00
|
|
|
"common-console" # shared stuff for interactive local sessions
|
2006-12-11 15:32:10 +00:00
|
|
|
]
|
2009-05-28 12:56:56 +00:00
|
|
|
);
|
2007-03-30 12:55:09 +00:00
|
|
|
|
2009-01-02 16:06:52 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
let
|
2009-05-19 23:51:13 +00:00
|
|
|
inherit (pkgs.stringsWithDeps) noDepEntry fullDepEntry packEntry;
|
2009-01-02 16:06:52 +00:00
|
|
|
|
|
|
|
copyScript = {source, target, mode ? "644", own ? "root.root"}:
|
2009-05-28 12:06:54 +00:00
|
|
|
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"
|
|
|
|
'';
|
2009-01-02 16:06:52 +00:00
|
|
|
|
|
|
|
makeEtc = import ../helpers/make-etc.nix {
|
|
|
|
inherit (pkgs) stdenv;
|
|
|
|
configFiles = configFiles ++ config.environment.etc;
|
|
|
|
};
|
|
|
|
in
|
2008-06-11 23:06:53 +00:00
|
|
|
|
2009-01-02 16:06:52 +00:00
|
|
|
{
|
|
|
|
require = [
|
|
|
|
option
|
|
|
|
|
|
|
|
# config.system.build
|
2009-05-25 14:19:33 +00:00
|
|
|
# ../system/system-options.nix
|
2009-01-02 16:06:52 +00:00
|
|
|
|
|
|
|
# config.system.activationScripts
|
2009-05-25 14:19:33 +00:00
|
|
|
# ../system/activate-configuration.nix
|
2009-01-02 16:06:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
system = {
|
|
|
|
build = {
|
|
|
|
etc = makeEtc;
|
|
|
|
};
|
|
|
|
|
|
|
|
activationScripts = {
|
2009-05-19 23:51:13 +00:00
|
|
|
etc = fullDepEntry ''
|
2009-01-02 16:06:52 +00: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
|
|
|
|
'' [
|
2009-05-20 01:35:46 +00:00
|
|
|
"systemConfig"
|
|
|
|
"defaultPath" # path to cp, chmod, chown
|
|
|
|
"stdio"
|
2009-01-02 16:06:52 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2007-02-26 21:18:13 +00:00
|
|
|
}
|