Skip to content

Commit

Permalink
feat: remove .nmconnection from the end of connection names
Browse files Browse the repository at this point in the history
  • Loading branch information
Janik-Haag committed Jan 29, 2024
1 parent 393da50 commit 27e200a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# NetworkManager to Nix

This is a really hacky script (really please don't look at the source code) that converts every .nmconnection file in the current folder to the nix code that is expected by `networking.networkmanager.ensure-profiles.profiles` which was introduced in [NixOS/nixpkgs/#254647](https://github.com/NixOS/nixpkgs/pull/254647)
This is a really dumb script that converts every .nmconnection file in the current directory to the nix code that is expected by `networking.networkmanager.ensure-profiles.profiles` which was introduced in [NixOS/nixpkgs/#254647](https://github.com/NixOS/nixpkgs/pull/254647)
You will have to do some manual escaping for connection names with special characters

You probably want to run this script in `/etc/NetworkManager/system-connections/` (default profile storage) or `/run/NetworkManager/system-connections` (temporary profile storage) both of the folders are only readable by the root user so you need to execute the script with root permissions aka sudo. For more details about the locations feel free to read [redhat's docs](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/assembly_networkmanager-connection-profiles-in-keyfile-format_configuring-and-managing-networking)

Expand Down
4 changes: 2 additions & 2 deletions nm2nix.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
for i in nmfiles:
config = configparser.ConfigParser()
config.read(i)
print(f" {i} = {{")
connection_name = i.strip(".nmconnection")
print(f" {connection_name} = {{")
for section in config.sections():
print(f" {section} = {{")
for key in config[section]:
print(f' {key} = "{config[section][key]}";')
print(" };")
print(" };")

print("};")

0 comments on commit 27e200a

Please sign in to comment.