nix-community / NixOS-WSL

NixOS on WSL(2) [maintainer=@nzbr]
Apache License 2.0
1.87k stars 119 forks source link

Make configuration.nix writeable by root #384

Open nzbr opened 10 months ago

nzbr commented 10 months ago

When importing a fresh tarball, /etc/nixos/configuration.nix is set to read-only. We should make the file writeable by root in the tarball builder

aikooo7 commented 10 months ago

Hello, I will try to implement this, I will keep you updated if I need anything

aikooo7 commented 10 months ago

Hello again @nzbr , I got a few issue so I want to know how should I try to debug it further, the three changes I tried:

--- a/modules/build-tarball.nix
+++ b/modules/build-tarball.nix
@@ -85,6 +85,7 @@ in
           mkdir -p "$root/etc/nixos"
           cp -R ${lib.cleanSource cfg.configPath}/. "$root/etc/nixos"
           chmod -R u+w "$root/etc/nixos"
+          chown -R 1000 /etc/nixos
         ''}

         echo "[NixOS-WSL] Compressing..."

AND

--- a/modules/build-tarball.nix
+++ b/modules/build-tarball.nix
@@ -85,6 +85,7 @@ in
           mkdir -p "$root/etc/nixos"
           cp -R ${lib.cleanSource cfg.configPath}/. "$root/etc/nixos"
           chmod -R u+w "$root/etc/nixos"
+          chown -R 1000 "$root/etc/nixos"
         ''}

         echo "[NixOS-WSL] Compressing..."

AND

--- a/modules/build-tarball.nix
+++ b/modules/build-tarball.nix
@@ -85,6 +85,7 @@ in
           mkdir -p "$root/etc/nixos"
           cp -R ${lib.cleanSource cfg.configPath}/. "$root/etc/nixos"
           chmod -R u+w "$root/etc/nixos"
+          chown -R nixos /etc/nixos
         ''}

         echo "[NixOS-WSL] Compressing..."
nzbr commented 10 months ago

Changing the owner to the default user shouldn't be necessary. It's fine if the file can only be edited by root. Given that the needed chmod call is already there, I suspect that the permissions get lost when creating the tar file for some reason

aikooo7 commented 10 months ago

I suspect that the permissions get lost when creating the tar file for some reason

That is what I was thinking too, so maybe we could do it in the first time the system is runned like the welcome message?

nzbr commented 10 months ago

Good idea. I like it. It's probably best to put it in an activation script

aikooo7 commented 10 months ago

Good idea. I like it. It's probably best to put it in an activation script

I don't like the idea of a activation script since I still want give the user a way to change the permissions for whatever they want, Which is impossible if the permissions are changed everytime the system is rebuilt