mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-18 07:46:09 +01:00
asterisk: Create symlinks for each config individually
This commit refactors the way how configuration files are deployed to the `/etc/asterisk` directory. The current solution builds a Nix derivation containing all config files and symlinks it to `/etc/asterisk`. The problem with that approach is that it is not possible to provide additional configuration that should not be written to the Nix store, i.e. files containing credentials. The proposed solution changes the creation of configuration files so that each configuration file gets symlinked to `/etc/asterisk` individually so that it becomes possible to provide additional config files to `/etc/asterisk` as well.
This commit is contained in:
parent
71285d11fd
commit
917be9fa32
1 changed files with 11 additions and 43 deletions
|
@ -14,28 +14,9 @@ let
|
|||
|
||||
# Add filecontents from files of useTheseDefaultConfFiles to confFiles, do not override
|
||||
defaultConfFiles = subtractLists (attrNames cfg.confFiles) cfg.useTheseDefaultConfFiles;
|
||||
allConfFiles =
|
||||
cfg.confFiles //
|
||||
builtins.listToAttrs (map (x: { name = x;
|
||||
value = builtins.readFile (cfg.package + "/etc/asterisk/" + x); })
|
||||
defaultConfFiles);
|
||||
|
||||
asteriskEtc = pkgs.stdenv.mkDerivation
|
||||
((mapAttrs' (name: value: nameValuePair
|
||||
# Fudge the names to make bash happy
|
||||
((replaceChars ["."] ["_"] name) + "_")
|
||||
(value)
|
||||
) allConfFiles) //
|
||||
{
|
||||
confFilesString = concatStringsSep " " (
|
||||
attrNames allConfFiles
|
||||
);
|
||||
|
||||
name = "asterisk-etc";
|
||||
|
||||
allConfFiles = {
|
||||
# Default asterisk.conf file
|
||||
# (Notice that astetcdir will be set to the path of this derivation)
|
||||
asteriskConf = ''
|
||||
"asterisk.conf".text = ''
|
||||
[directories]
|
||||
astetcdir => /etc/asterisk
|
||||
astmoddir => ${cfg.package}/lib/asterisk/modules
|
||||
|
@ -48,43 +29,28 @@ let
|
|||
astrundir => /run/asterisk
|
||||
astlogdir => /var/log/asterisk
|
||||
astsbindir => ${cfg.package}/sbin
|
||||
${cfg.extraConfig}
|
||||
'';
|
||||
extraConf = cfg.extraConfig;
|
||||
|
||||
# Loading all modules by default is considered sensible by the authors of
|
||||
# "Asterisk: The Definitive Guide". Secure sites will likely want to
|
||||
# specify their own "modules.conf" in the confFiles option.
|
||||
modulesConf = ''
|
||||
"modules.conf".text = ''
|
||||
[modules]
|
||||
autoload=yes
|
||||
'';
|
||||
|
||||
# Use syslog for logging so logs can be viewed with journalctl
|
||||
loggerConf = ''
|
||||
"logger.conf".text = ''
|
||||
[general]
|
||||
|
||||
[logfiles]
|
||||
syslog.local0 => notice,warning,error
|
||||
'';
|
||||
} //
|
||||
mapAttrs (name: text: { inherit text; }) cfg.confFiles //
|
||||
listToAttrs (map (x: nameValuePair x { source = cfg.package + "/etc/asterisk/" + x; }) defaultConfFiles);
|
||||
|
||||
buildCommand = ''
|
||||
mkdir -p "$out"
|
||||
|
||||
# Create asterisk.conf, pointing astetcdir to the path of this derivation
|
||||
echo "$asteriskConf" | sed "s|@out@|$out|g" > "$out"/asterisk.conf
|
||||
echo "$extraConf" >> "$out"/asterisk.conf
|
||||
|
||||
echo "$modulesConf" > "$out"/modules.conf
|
||||
|
||||
echo "$loggerConf" > "$out"/logger.conf
|
||||
|
||||
# Config files specified in confFiles option override all other files
|
||||
for i in $confFilesString; do
|
||||
conf=$(echo "$i"_ | sed 's/\./_/g')
|
||||
echo "''${!conf}" > "$out"/"$i"
|
||||
done
|
||||
'';
|
||||
});
|
||||
in
|
||||
|
||||
{
|
||||
|
@ -209,7 +175,9 @@ in
|
|||
config = mkIf cfg.enable {
|
||||
environment.systemPackages = [ cfg.package ];
|
||||
|
||||
environment.etc.asterisk.source = asteriskEtc;
|
||||
environment.etc = mapAttrs' (name: value:
|
||||
nameValuePair "asterisk/${name}" value
|
||||
) allConfFiles;
|
||||
|
||||
users.users.asterisk =
|
||||
{ name = asteriskUser;
|
||||
|
|
Loading…
Reference in a new issue