git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/tinc: allow configuration of RSA key file

This is necessary for VPNs where some of the nodes run pre-1.1 versions. Most of Linux distros [0] and even the nixpkgs.tinc attribute run on that version, so it might be useful to have that option. [0] https://repology.org/project/tinc/versions

commit1192255677b4cd5f328a601c562c456ae06eb33d authorJustin Humm <justin.humm@posteo.de> dateSat 25 Apr 2020, 22:04 (7 years ago) parente3cba5a
1 file changed+14−2
nixos/modules/services/networking/tinc.nix+14−2
nixos/modules/services/networking/tinc.nix+14−2
@@ -48,6 +48,14 @@ in
4848 '';
4949 };
5050
51+ rsaPrivateKeyFile = mkOption {
52+ default = null;
53+ type = types.nullOr types.path;
54+ description = ''
55+ Path of the private RSA keyfile.
56+ '';
57+ };
58+
5159 debugLevel = mkOption {
5260 default = 0;
5361 type = types.addCheck types.int (l: l >= 0 && l <= 5);
@@ -139,6 +147,7 @@ in
139147 Name = ${if data.name == null then "$HOST" else data.name}
140148 DeviceType = ${data.interfaceType}
141149 ${optionalString (data.ed25519PrivateKeyFile != null) "Ed25519PrivateKeyFile = ${data.ed25519PrivateKeyFile}"}
150+ ${optionalString (data.rsaPrivateKeyFile != null) "PrivateKeyFile = ${data.rsaPrivateKeyFile}"}
142151 ${optionalString (data.listenAddress != null) "ListenAddress = ${data.listenAddress}"}
143152 ${optionalString (data.bindToAddress != null) "BindToAddress = ${data.bindToAddress}"}
144153 Interface = tinc.${network}
@@ -170,12 +179,15 @@ in
170179 # Determine how we should generate our keys
171180 if type tinc >/dev/null 2>&1; then
172181 # Tinc 1.1+ uses the tinc helper application for key generation
173− ${if data.ed25519PrivateKeyFile != null then " # Keyfile managed by nix" else ''
182+ ${if data.ed25519PrivateKeyFile != null then " # ed25519 Keyfile managed by nix" else ''
174183 # Prefer ED25519 keys (only in 1.1+)
175184 [ -f "/etc/tinc/${network}/ed25519_key.priv" ] || tinc -n ${network} generate-ed25519-keys
176185 ''}
177− # Otherwise use RSA keys
186+ ${if data.rsaPrivateKeyFile != null then " # RSA Keyfile managed by nix" else ''
178187 [ -f "/etc/tinc/${network}/rsa_key.priv" ] || tinc -n ${network} generate-rsa-keys 4096
188+ ''}
189+ # In case there isn't anything to do
190+ true
179191 else
180192 # Tinc 1.0 uses the tincd application
181193 [ -f "/etc/tinc/${network}/rsa_key.priv" ] || tincd -n ${network} -K 4096