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 = {
|
2009-05-28 15:17:56 +02:00
|
|
|
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-01-02 17:06:52 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
let
|
|
|
|
|
|
|
|
copyScript = {source, target, mode ? "644", own ? "root.root"}:
|
2009-05-28 14:06:54 +02: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 17:06:52 +01:00
|
|
|
|
2009-08-16 15:14:33 +02:00
|
|
|
makeEtc = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "etc";
|
|
|
|
|
|
|
|
builder = ./make-etc.sh;
|
|
|
|
|
2009-10-23 22:30:12 +02:00
|
|
|
inherit (pkgs) coreutils;
|
|
|
|
|
2009-08-16 15:14:33 +02:00
|
|
|
/* !!! Use toXML. */
|
|
|
|
sources = map (x: x.source) config.environment.etc;
|
|
|
|
targets = map (x: x.target) config.environment.etc;
|
|
|
|
modes = map (x: if x ? mode then x.mode else "symlink") config.environment.etc;
|
2009-01-02 17:06:52 +01:00
|
|
|
};
|
2009-08-16 15:14:33 +02:00
|
|
|
|
2009-01-02 17:06:52 +01:00
|
|
|
in
|
2008-06-12 01:06:53 +02:00
|
|
|
|
2009-01-02 17:06:52 +01:00
|
|
|
{
|
2009-05-28 15:17:56 +02:00
|
|
|
require = [option];
|
2009-01-02 17:06:52 +01:00
|
|
|
|
|
|
|
system = {
|
|
|
|
build = {
|
|
|
|
etc = makeEtc;
|
|
|
|
};
|
|
|
|
|
|
|
|
activationScripts = {
|
2009-05-28 15:17:56 +02:00
|
|
|
etc = pkgs.lib.fullDepEntry ''
|
2009-01-02 17:06:52 +01:00
|
|
|
# Set up the statically computed bits of /etc.
|
2009-08-03 14:36:15 +02:00
|
|
|
echo "setting up /etc..."
|
2009-10-24 02:03:13 +02:00
|
|
|
if [ "$(readlink /etc/kill-etc)" != "${makeEtc}/bin/kill-etc" ]; then
|
|
|
|
/etc/kill-etc || true
|
|
|
|
${makeEtc}/bin/fill-etc
|
|
|
|
echo -e "#! /bin/sh\n${makeEtc}/bin/kill-etc\n${makeEtc}/bin/fill-etc" > /etc/refill-etc
|
|
|
|
chmod 0755 /etc/refill-etc
|
|
|
|
echo "/etc is set up"
|
|
|
|
else
|
|
|
|
echo "/etc unchanged"
|
|
|
|
fi
|
2009-01-02 17:06:52 +01:00
|
|
|
'' [
|
2009-05-20 03:35:46 +02:00
|
|
|
"systemConfig"
|
|
|
|
"defaultPath" # path to cp, chmod, chown
|
|
|
|
"stdio"
|
2009-01-02 17:06:52 +01:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2007-02-26 22:18:13 +01:00
|
|
|
}
|