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;
|
|
|
|
|
|
|
|
/* !!! 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-01-02 17:06:52 +01:00
|
|
|
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 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
|
|
|
}
|