So, continuing to try ton configure a VPN server from a .nix
file, I’m trying to set the configuration file from a immutable file + custom information in a different file.
Let me give some example to try to be clear:
So, the first variable is declared in the let
session:
This file is generate using a .tpl
file as a template:
let
Template = nixpkgs.writeText "config-server.conf" (builtins.readFile (builtins.toPath (../templates/server.tpl)));
ConfigFile = "/tmp/server.conf";
So, those lines creates two variables, one called Template
with the values from the /template/server.tpl
file.
Te second created a variable called ConfigFile
which contains the path to the configuration file, in this case /tmp/server.conf
.
Ok, after that on the “in” session, I have a system.activationScripts
that update the value of the file /tmp/server.conf
system.activationScripts.script.text = ''
addr=${cidr}
instanceName="$(cat /etc/ec2-tags/name)"
rm -f ${ConfigFile}
if [ $instanceName == instance-1 ]; then
addr="''${addr/0./1.}"
elif [ $instanceName == instance-2 ]; then
addr="''${addr/0./2.}"
fi
echo -e "server $addr 255.255.255.0" >> ${ConfigFile}
'';
So, on the activation stage the value of the ${ConfigFile}
(/tmp/server.conf) is updated based on instance name. (this part is working, I checked that the file was updated.)
Then, on the systemd.service
ExecStartPre
, I want to merge the value of the immutable file ${Template}
into the ${ConfigFile}
(/tmp/server.conf)
ExecStartPre content:
ExecStartPre = [
''${nixpkgs.bash}/bin/bash -c "${nixpkgs.coreutils}/bin/cat ${Template} >> ${ConfigFile}"''
];
However is not working.
After the activation the ${ConfigFile}
(/tmp/server.conf) have only the value set on the activation script and the value of the ${Template} was not merged.
Any hint where Im mistaking ???