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 23:12:02 +01: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
|
|
|
|
2009-01-02 16:06:52 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
let
|
2009-05-20 00:51:13 +01: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 13:06:54 +01: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;
|
2009-05-28 14:10:02 +01:00
|
|
|
configFiles = config.environment.etc;
|
2009-01-02 16:06:52 +00:00
|
|
|
};
|
|
|
|
in
|
2008-06-12 00:06:53 +01:00
|
|
|
|
2009-01-02 16:06:52 +00:00
|
|
|
{
|
|
|
|
require = [
|
|
|
|
option
|
|
|
|
|
|
|
|
# config.system.build
|
2009-05-25 15:19:33 +01:00
|
|
|
# ../system/system-options.nix
|
2009-01-02 16:06:52 +00:00
|
|
|
|
|
|
|
# config.system.activationScripts
|
2009-05-25 15:19:33 +01:00
|
|
|
# ../system/activate-configuration.nix
|
2009-01-02 16:06:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
system = {
|
|
|
|
build = {
|
|
|
|
etc = makeEtc;
|
|
|
|
};
|
|
|
|
|
|
|
|
activationScripts = {
|
2009-05-20 00:51:13 +01: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 02:35:46 +01: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
|
|
|
}
|