{ config, lib, pkgs, ... }: with lib; let text = import ./write-text.nix { inherit lib; mkTextDerivation = name: text: pkgs.writeText "etc-${name}" text; }; etc = filter (f: f.enable) (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 /etc. ''; }; }; config = { system.build.etc = pkgs.runCommand "etc" {} '' mkdir -p $out/etc cd $out/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: /etc/$link is a file, 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 ''; }; }