2016-11-05 21:47:09 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
text = import ./write-text.nix {
|
|
|
|
inherit lib;
|
|
|
|
mkTextDerivation = name: text: pkgs.writeText "etc-${name}" text;
|
|
|
|
};
|
|
|
|
|
2016-12-15 13:08:48 +00:00
|
|
|
hasDir = path: length (splitString "/" path) > 1;
|
|
|
|
|
2016-11-05 21:47:09 +00:00
|
|
|
etc = filter (f: f.enable) (attrValues config.environment.etc);
|
2016-12-15 13:08:48 +00:00
|
|
|
etcDirs = filter (attr: hasDir attr.target) (attrValues config.environment.etc);
|
2016-11-05 21:47:09 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
|
|
|
|
environment.etc = mkOption {
|
|
|
|
type = types.loaOf (types.submodule text);
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Set of files that have to be linked in <filename>/etc</filename>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
|
|
|
system.build.etc = pkgs.runCommand "etc" {} ''
|
|
|
|
mkdir -p $out/etc
|
|
|
|
cd $out/etc
|
2016-12-15 13:08:48 +00:00
|
|
|
${concatMapStringsSep "\n" (attr: "mkdir -p $(dirname '${attr.target}')") etc}
|
2016-11-05 21:47:09 +00:00
|
|
|
${concatMapStringsSep "\n" (attr: "ln -s '${attr.source}' '${attr.target}'") etc}
|
|
|
|
'';
|
|
|
|
|
|
|
|
system.activationScripts.etc.text = ''
|
|
|
|
# Set up the statically computed bits of /etc.
|
|
|
|
echo "setting up /etc..."
|
|
|
|
|
|
|
|
ln -sfn "$(readlink -f $systemConfig/etc)" /etc/static
|
|
|
|
|
|
|
|
for link in $(ls /etc/static/); do
|
|
|
|
if [ -e "/etc/$link" ]; then
|
|
|
|
if [ ! -L "/etc/$link" ]; then
|
2016-12-19 20:53:14 +00:00
|
|
|
echo "warning: not linking /etc/static/$link because /etc/$link exists, skipping..." >&2
|
2016-11-05 21:47:09 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
ln -sfn "/etc/static/$link" "/etc/$link"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
for link in $(find /etc/ -maxdepth 1 -type l); do
|
|
|
|
if [[ "$(readlink $link)" == /etc/static/* ]]; then
|
|
|
|
if [ ! -e "$(readlink -f $link)" ]; then
|
|
|
|
rm $link
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|