1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-14 11:57:34 +00:00
nix-darwin/modules/system/etc.nix

68 lines
1.6 KiB
Nix
Raw Normal View History

{ 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;
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);
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}
${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
echo "warning: not linking /etc/static/$link because /etc/$link exists, skipping..." >&2
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
'';
};
}