From a1355100471301d0719a667c57ae86abc001e7d4 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Mon, 3 Mar 2025 23:44:37 +0100 Subject: [PATCH] Fix iwd space handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ref man iwd.network: > Key-value lines contain a setting key, an equal sign and the value of > the setting. Whitespace preceding the key, the equal sign or the value, > is ignored. The key must be a continuous string of alphanumeric and > underscore characters and minus signs only. The value starts at the > first non-whitespace character after the first equal sign on the line > and ends at the end of the line and must be correctly UTF-8-encoded. > […] > String values, including file > paths and hexstrings, are written as is except for five characters that > may be backslash-escaped: space, \t, \r, \n and backslash itself. > The latter three must be escaped. A space character must be escaped if > it is the first character in the value string and is written as \s. I guess this is what is expected then: ``` $ echo -e " \t \r \\ " \ $ echo -e " \t \r \\ " | sed "s=\\\=\\\\\\\=g;s=\t=\\\t=g;s=\r=\\\r=g;s=^ =\\\s=" \s \t \r \\ ``` --- clanModules/iwd/roles/default.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clanModules/iwd/roles/default.nix b/clanModules/iwd/roles/default.nix index aa2c3ed1a..91cc34ad8 100644 --- a/clanModules/iwd/roles/default.nix +++ b/clanModules/iwd/roles/default.nix @@ -1,4 +1,4 @@ -{ lib, config, ... }: +{ lib, config, pkgs, ... }: let cfg = config.clan.iwd; @@ -12,12 +12,13 @@ let { secret.${secret_name} = { }; generator.prompt = "Wifi password for '${value.ssid}'"; + # ref. man iwd.network generator.script = '' config=" [Settings] AutoConnect=${if value.AutoConnect then "true" else "false"} [Security] - Passphrase=\"$prompt_value\" + Passphrase=$(echo -e "$prompt_value" | ${lib.getExe pkgs.gnused} "s=\\\=\\\\\\\=g;s=\t=\\\t=g;s=\r=\\\r=g;s=^ =\\\s=") " echo "$config" > "$secrets/${secret_name}" '';