Commit 87051a8f authored by Felix Buehler's avatar Felix Buehler
Browse files

nixos/sogo: prefer 'install' over 'chmod'/'chown'

parent 67ab30a1
Loading
Loading
Loading
Loading
+2 −6
Original line number Diff line number Diff line
@@ -2,17 +2,13 @@
  cfg = config.services.sogo;

  preStart = pkgs.writeShellScriptBin "sogo-prestart" ''
    touch /etc/sogo/sogo.conf
    chown sogo:sogo /etc/sogo/sogo.conf
    chmod 640 /etc/sogo/sogo.conf

    ${if (cfg.configReplaces != {}) then ''
      # Insert secrets
      ${concatStringsSep "\n" (mapAttrsToList (k: v: ''export ${k}="$(cat "${v}" | tr -d '\n')"'') cfg.configReplaces)}

      ${pkgs.perl}/bin/perl -p ${concatStringsSep " " (mapAttrsToList (k: v: '' -e 's/${k}/''${ENV{"${k}"}}/g;' '') cfg.configReplaces)} /etc/sogo/sogo.conf.raw > /etc/sogo/sogo.conf
      ${pkgs.perl}/bin/perl -p ${concatStringsSep " " (mapAttrsToList (k: v: '' -e 's/${k}/''${ENV{"${k}"}}/g;' '') cfg.configReplaces)} /etc/sogo/sogo.conf.raw | install -m 640 -o sogo -g sogo /dev/stdin /etc/sogo/sogo.conf
    '' else ''
      cp /etc/sogo/sogo.conf.raw /etc/sogo/sogo.conf
      install -m 640 -o sogo -g sogo /etc/sogo/sogo.conf.raw /etc/sogo/sogo.conf
    ''}
  '';