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.
|
|
|
|
|
";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
let
|
2008-11-23 01:29:20 +00:00
|
|
|
|
nixEnvVars = config.nix.envVars;
|
|
|
|
|
modulesTree = config.system.modulesTree;
|
|
|
|
|
nssModulesPath = config.system.nssModules.path;
|
2009-01-02 16:06:52 +00:00
|
|
|
|
wrapperDir = config.system.wrapperDir;
|
|
|
|
|
systemPath = config.system.path;
|
2009-01-02 19:41:39 +00:00
|
|
|
|
binsh = config.system.build.binsh;
|
2007-06-10 21:02:07 +01:00
|
|
|
|
|
2007-11-09 18:49:45 +00:00
|
|
|
|
optional = pkgs.lib.optional;
|
2007-01-16 16:09:43 +00:00
|
|
|
|
|
2007-06-10 21:02:07 +01: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 21:02:07 +01:00
|
|
|
|
|
|
|
|
|
pamConsolePerms = ./security/console.perms;
|
|
|
|
|
|
2009-01-02 16:06:52 +00:00
|
|
|
|
# These should be moved into the corresponding configuration files.
|
2006-12-11 15:32:10 +00: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 12:33:21 +00:00
|
|
|
|
{ # RPC program numbers.
|
|
|
|
|
source = pkgs.glibc + "/etc/rpc";
|
|
|
|
|
target = "rpc";
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-11 15:32:10 +00:00
|
|
|
|
{ # Hostname-to-IP mappings.
|
2008-01-04 17:05:48 +00:00
|
|
|
|
source = pkgs.substituteAll {
|
|
|
|
|
src = ./hosts;
|
|
|
|
|
extraHosts = config.networking.extraHosts;
|
|
|
|
|
};
|
2006-12-11 15:32:10 +00:00
|
|
|
|
target = "hosts";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{ # Friendly greeting on the virtual consoles.
|
2008-01-04 17:05:48 +00:00
|
|
|
|
source = pkgs.writeText "issue" ''
|
|
|
|
|
|
|
|
|
|
[1;32m${config.services.mingetty.greetingLine}[0m
|
|
|
|
|
${config.services.mingetty.helpLine}
|
|
|
|
|
|
|
|
|
|
'';
|
2006-12-11 15:32:10 +00:00
|
|
|
|
target = "issue";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{ # Configuration for pwdutils (login, passwd, useradd, etc.).
|
|
|
|
|
# You cannot login without it!
|
2007-03-30 13:59:43 +01:00
|
|
|
|
source = ./login.defs;
|
2006-12-11 15:32:10 +00:00
|
|
|
|
target = "login.defs";
|
2009-01-02 16:06:52 +00:00
|
|
|
|
}
|
2006-12-11 15:32:10 +00:00
|
|
|
|
|
|
|
|
|
{ # Configuration for passwd and friends (e.g., hash algorithm
|
|
|
|
|
# for /etc/passwd).
|
2007-03-30 13:59:43 +01:00
|
|
|
|
source = ./default/passwd;
|
2006-12-11 15:32:10 +00:00
|
|
|
|
target = "default/passwd";
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-20 13:30:14 +00:00
|
|
|
|
{ # Configuration for useradd.
|
|
|
|
|
source = pkgs.substituteAll {
|
2007-03-30 13:59:43 +01:00
|
|
|
|
src = ./default/useradd;
|
2009-01-02 16:06:52 +00:00
|
|
|
|
defaultShell = config.system.shell;
|
2007-03-20 13:30:14 +00:00
|
|
|
|
};
|
|
|
|
|
target = "default/useradd";
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-22 17:28:25 +00:00
|
|
|
|
{ # Dhclient hooks for emitting ip-up/ip-down events.
|
|
|
|
|
source = pkgs.substituteAll {
|
2007-03-30 13:59:43 +01:00
|
|
|
|
src = ./dhclient-exit-hooks;
|
2007-01-23 10:22:00 +00:00
|
|
|
|
inherit (pkgs) upstart glibc;
|
2006-12-22 17:28:25 +00:00
|
|
|
|
};
|
|
|
|
|
target = "dhclient-exit-hooks";
|
|
|
|
|
}
|
2007-01-15 14:43:56 +00:00
|
|
|
|
|
2008-03-12 10:18:11 +00:00
|
|
|
|
{ # Script executed when the shell starts as a non-login shell (system-wide version).
|
2007-01-15 14:43:56 +00:00
|
|
|
|
source = pkgs.substituteAll {
|
2008-07-16 17:01:09 +01:00
|
|
|
|
src = ./bashrc.sh;
|
2008-03-17 13:58:57 +00:00
|
|
|
|
inherit systemPath wrapperDir modulesTree nssModulesPath;
|
2008-01-06 18:45:13 +00:00
|
|
|
|
inherit (pkgs) glibc;
|
2007-11-09 18:49:45 +00:00
|
|
|
|
timeZone = config.time.timeZone;
|
|
|
|
|
defaultLocale = config.i18n.defaultLocale;
|
2007-11-15 17:16:16 +00:00
|
|
|
|
inherit nixEnvVars;
|
2007-01-15 14:43:56 +00:00
|
|
|
|
};
|
2008-07-16 17:01:09 +01:00
|
|
|
|
target = "bashrc";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{ # Script executed when the shell starts as a login shell.
|
|
|
|
|
source = ./profile.sh;
|
2007-01-15 14:43:56 +00:00
|
|
|
|
target = "profile";
|
|
|
|
|
}
|
2007-01-16 16:09:43 +00:00
|
|
|
|
|
2007-05-02 10:55:35 +01:00
|
|
|
|
{ # Configuration for readline in bash.
|
|
|
|
|
source = ./inputrc;
|
|
|
|
|
target = "inputrc";
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-05 11:19:51 +00:00
|
|
|
|
{ # Nix configuration.
|
2009-01-02 19:41:39 +00:00
|
|
|
|
source =
|
|
|
|
|
let
|
|
|
|
|
# Tricky: if we're using a chroot for builds, then we need
|
|
|
|
|
# /bin/sh in the chroot (our own compromise to purity).
|
|
|
|
|
# However, since /bin/sh is a symlink to some path in the
|
|
|
|
|
# Nix store, which furthermore has runtime dependencies on
|
|
|
|
|
# other paths in the store, we need the closure of /bin/sh
|
|
|
|
|
# in `build-chroot-dirs' - otherwise any builder that uses
|
|
|
|
|
# /bin/sh won't work.
|
|
|
|
|
refs = pkgs.writeReferencesToFile binsh;
|
|
|
|
|
in
|
|
|
|
|
pkgs.runCommand "nix.conf" {} ''
|
|
|
|
|
binshDeps=$(for i in $(cat ${refs}); do if test -d $i; then echo $i; fi; done)
|
|
|
|
|
cat > $out <<END
|
|
|
|
|
# WARNING: this file is generated.
|
|
|
|
|
build-users-group = nixbld
|
|
|
|
|
build-max-jobs = ${toString (config.nix.maxJobs)}
|
|
|
|
|
build-use-chroot = ${if config.nix.useChroot then "true" else "false"}
|
|
|
|
|
build-chroot-dirs = /dev /dev/pts /proc /bin $(echo $binshDeps)
|
|
|
|
|
${config.nix.extraOptions}
|
|
|
|
|
END
|
|
|
|
|
'';
|
2007-11-05 11:19:51 +00:00
|
|
|
|
target = "nix.conf"; # will be symlinked from /nix/etc/nix/nix.conf in activate-configuration.sh.
|
|
|
|
|
}
|
2007-11-08 18:15:12 +00:00
|
|
|
|
|
2008-03-12 10:18:11 +00:00
|
|
|
|
{ # Script executed when the shell starts as a non-login shell (user version).
|
|
|
|
|
source = ./skel/bashrc;
|
|
|
|
|
target = "skel/.bashrc";
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-16 13:59:03 +00: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 15:32:10 +00:00
|
|
|
|
]
|
|
|
|
|
|
2007-11-08 18:15:12 +00:00
|
|
|
|
# Configuration for ssmtp.
|
2007-11-09 18:49:45 +00:00
|
|
|
|
++ optional config.networking.defaultMailServer.directDelivery {
|
2008-01-04 17:05:48 +00:00
|
|
|
|
source = let cfg = config.networking.defaultMailServer; in pkgs.writeText "ssmtp.conf" ''
|
2008-04-24 13:36:50 +01:00
|
|
|
|
MailHub=${cfg.hostName}
|
|
|
|
|
FromLineOverride=YES
|
2008-01-04 17:05:48 +00: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 18:15:12 +00:00
|
|
|
|
target = "ssmtp/ssmtp.conf";
|
2007-11-09 18:49:45 +00:00
|
|
|
|
}
|
2007-01-22 16:42:29 +00:00
|
|
|
|
|
2007-01-16 16:09:43 +00:00
|
|
|
|
# LDAP configuration.
|
2007-11-09 18:49:45 +00:00
|
|
|
|
++ optional config.users.ldap.enable {
|
2007-04-10 15:10:45 +01:00
|
|
|
|
source = import ./ldap.conf.nix {
|
2007-01-16 16:09:43 +00:00
|
|
|
|
inherit (pkgs) writeText;
|
|
|
|
|
inherit config;
|
|
|
|
|
};
|
|
|
|
|
target = "ldap.conf";
|
2007-11-09 18:49:45 +00:00
|
|
|
|
}
|
2007-01-16 16:09:43 +00:00
|
|
|
|
|
2006-12-11 15:32:10 +00:00
|
|
|
|
# A bunch of PAM configuration files for various programs.
|
|
|
|
|
++ (map
|
|
|
|
|
(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 13:59:43 +01:00
|
|
|
|
src = ./pam.d + ("/" + program);
|
2007-06-10 21:02:07 +01:00
|
|
|
|
inherit (pkgs) pam_unix2 pam_console;
|
2007-01-16 16:09:43 +00:00
|
|
|
|
pam_ldap =
|
2007-06-10 21:02:07 +01: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 17:01:09 +01:00
|
|
|
|
inherit pamConsoleHandlers;
|
2007-06-10 21:02:07 +01:00
|
|
|
|
isLDAPEnabled = if isLDAPEnabled then "" else "#";
|
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"
|
2008-11-07 11:51:17 +00:00
|
|
|
|
"cups"
|
2007-01-30 15:03:43 +00:00
|
|
|
|
"common"
|
2007-06-10 21:02:07 +01:00
|
|
|
|
"common-console" # shared stuff for interactive local sessions
|
2006-12-11 15:32:10 +00:00
|
|
|
|
]
|
2007-03-30 13:55:09 +01:00
|
|
|
|
)
|
|
|
|
|
|
2007-11-15 17:16:16 +00: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";
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-12 00:06:53 +01:00
|
|
|
|
# unixODBC drivers (this solution is not perfect.. Because the user has to
|
|
|
|
|
# ask the admin to add a driver.. but it's an easy solution which works)
|
|
|
|
|
++ (let inis = config.environment.unixODBCDrivers pkgs;
|
2008-06-12 13:19:47 +01:00
|
|
|
|
in optional (inis != [] ) {
|
2008-06-12 00:06:53 +01:00
|
|
|
|
source = pkgs.writeText "odbcinst.ini" (pkgs.lib.concatStringsSep "\n" inis);
|
|
|
|
|
target = "odbcinst.ini";
|
|
|
|
|
})
|
2009-01-02 16:06:52 +00:00
|
|
|
|
;
|
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
inherit (pkgs.stringsWithDeps) noDepEntry FullDepEntry PackEntry;
|
|
|
|
|
|
|
|
|
|
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 00:06:53 +01:00
|
|
|
|
|
2009-01-02 16:06:52 +00:00
|
|
|
|
{
|
|
|
|
|
require = [
|
|
|
|
|
option
|
|
|
|
|
|
|
|
|
|
# config.system.build
|
|
|
|
|
(import ../system/system-options.nix)
|
|
|
|
|
|
|
|
|
|
# config.system.activationScripts
|
|
|
|
|
(import ../system/activate-configuration.nix)
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
system = {
|
|
|
|
|
build = {
|
|
|
|
|
etc = makeEtc;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
activationScripts = {
|
|
|
|
|
etc = FullDepEntry ''
|
|
|
|
|
# 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 21:18:13 +00:00
|
|
|
|
}
|