How to make nix not evaluate "${RANDOM}"

I would like to implement RFC 7844 DHCP anonymity settings in my nixos configuration, but I am running into a problem in that nix tries to evaluate "${RANDOM}" instead of writing that exact string to the Network Manager config file.

I want to use networking.networkmanager.connectionConfig to set connection.stable-id=${RANDOM} in my /etc/NetworkManager/NetworkManager.conf

When I set: networking.networkmanager.connectionConfig = { “connection.stable-id” = “${RANDOM}”; }; I get error: undefined variable ‘RANDOM’ when attempting to rebuild nixos.

How can I make nix not evaluate “${RANDOM}” and simply write that string to the target file?

You need to escape it, this should work

networking.networkmanager.connectionConfig = { "connection.stable-id" = "$\{RANDOM}"; };

2 Likes

That did the trick. Thank you.

Depends on the kind of string as well, see String interpolation - Nix 2.33.1 Reference Manual.

3 Likes