include('${nextcloud}/version.php');
$CONFIG = array (
// FIXME: change this value when nextcloud starts getting slow
- 'instanceid' => '${env.instance_id}1',
+ 'instanceid' => '${env.instance_id}',
'datadirectory' => '/var/lib/nextcloud/',
'passwordsalt' => '${env.password_salt}',
'debug' => false,
location = config.secrets.location;
keys = config.secrets.keys;
empty = pkgs.runCommand "empty" { preferLocalBuild = true; } "mkdir -p $out && touch $out/done";
+ fpath = v: "secrets/${v.dest}${lib.optionalString (v.isTemplated or true) ".gucci.tpl"}";
dumpKey = v: ''
mkdir -p secrets/$(dirname ${v.dest})
- echo -n ${lib.strings.escapeShellArg v.text} > secrets/${v.dest}
+ echo -n ${lib.strings.escapeShellArg v.text} > ${fpath v}
cat >> mods <<EOF
- ${v.user or "root"} ${v.group or "root"} ${v.permissions or "0600"} secrets/${v.dest}
+ ${v.user or "root"} ${v.group or "root"} ${v.permissions or "0600"} ${fpath v}
EOF
'';
secrets = pkgs.runCommand "secrets.tar" {} ''
if [ -n "$TMP" ]; then
install -m0750 -o root -g keys -d $TMP
${pkgs.gnutar}/bin/tar --strip-components 1 -C $TMP -xf /run/keys/secrets.tar
- sha512sum /run/keys/secrets.tar > $TMP/currentSecrets
+ if [ -f /run/keys/vars.yml ]; then
+ find $TMP -name "*.gucci.tpl" -exec \
+ /bin/sh -c 'f="{}"; ${pkgs.gucci}/bin/gucci -f /run/keys/vars.yml "$f" > "''${f%.gucci.tpl}"; touch --reference "$f" ''${f%.gucci.tpl} ; chmod --reference="$f" ''${f%.gucci.tpl} ; chown --reference="$f" ''${f%.gucci.tpl}' \;
+ sha512sum /run/keys/secrets.tar /run/keys/vars.yml > $TMP/currentSecrets
+ else
+ sha512sum /run/keys/secrets.tar > $TMP/currentSecrets
+ fi
find $TMP -type d -exec chown root:keys {} \; -exec chmod o-rx {} \;
- ${pkgs.rsync}/bin/rsync -O -c -av --delete $TMP/ ${location}
+ ${pkgs.rsync}/bin/rsync --exclude="*.gucci.tpl" -O -c -av --delete $TMP/ ${location}
rm -rf $TMP
fi
fi
fi
'';
};
+
system.extraDependencies = [ secrets ];
+ deployment.secrets."secret_vars.yml" = {
+ source = builtins.toString <privateFiles/vars.yml>;
+ destination = "/run/keys/vars.yml";
+ owner.user = "root";
+ owner.group = "root";
+ permissions = "0400";
+ };
deployment.secrets."secrets.tar" = {
source = "${secrets}";
destination = "/run/keys/secrets.tar";