Skip to content

Commit c4b7e5f

Browse files
authored
Merge pull request #79 from nzbr/mount-fix
Fix Windows File Systems not being mounted on first start when using the Installer
2 parents f0dd180 + 67b9d7c commit c4b7e5f

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

modules/installer.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ with builtins; with lib; {
5454

5555
contents = [
5656
{ source = config.environment.etc."wsl.conf".source; target = "/etc/wsl.conf"; }
57+
{ source = config.environment.etc."fstab".source; target = "/etc/fstab"; }
5758
{ source = passwd; target = "/etc/passwd"; }
59+
{ source = "${pkgs.busybox}/bin/busybox"; target = "/bin/sh"; }
60+
{ source = "${pkgs.busybox}/bin/busybox"; target = "/bin/mount"; }
5861
];
5962
};
6063

modules/wsl-distro.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ with builtins; with lib;
4747
config =
4848
let
4949
cfg = config.wsl;
50-
syschdemd = import ../syschdemd.nix { inherit lib pkgs config; defaultUser = cfg.defaultUser; };
50+
syschdemd = import ../syschdemd.nix { inherit lib pkgs config; defaultUser = cfg.defaultUser; defaultUserHome = config.users.users.${cfg.defaultUser}.home; };
5151
in
5252
mkIf cfg.enable {
5353

syschdemd.nix

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
{ lib, pkgs, config, defaultUser, ... }:
1+
{ lib
2+
, pkgs
3+
, config
4+
, defaultUser
5+
, defaultUserHome ? "/home/${defaultUser}"
6+
, ...
7+
}:
28

39
pkgs.substituteAll {
410
name = "syschdemd";
@@ -8,8 +14,8 @@ pkgs.substituteAll {
814

915
buildInputs = with pkgs; [ daemonize ];
1016

17+
inherit defaultUser defaultUserHome;
1118
inherit (pkgs) daemonize;
12-
inherit defaultUser;
1319
inherit (config.security) wrapperDir;
1420
fsPackagesPath = lib.makeBinPath config.system.fsPackages;
1521

syschdemd.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fi
5656
# Pass external environment but filter variables specific to root user.
5757
exportCmd="$(export -p | $sw/grep -vE ' (HOME|LOGNAME|SHELL|USER)='); export WSLPATH=\"$PATH\"; export INSIDE_NAMESPACE=true"
5858

59-
if [ -z "${INSIDE_NAMESPACE:-}" ]; then
59+
if [[ -z "${INSIDE_NAMESPACE:-}" ]]; then
6060

6161
# Test whether systemd is still alive if it was started previously
6262
if ! [ -d "/proc/$(</run/systemd.pid)" ]; then
@@ -65,6 +65,12 @@ if [ -z "${INSIDE_NAMESPACE:-}" ]; then
6565
start_systemd
6666
fi
6767

68+
# If we are currently in /root, this is probably because the directory that WSL was started is inaccessible
69+
# cd to the user's home to prevent a warning about permission being denied on /root
70+
if [[ $PWD == "/root" ]]; then
71+
cd @defaultUserHome@
72+
fi
73+
6874
exec $sw/nsenter -t $(</run/systemd.pid) -p -m -- $sw/machinectl -q \
6975
--uid=@defaultUser@ shell .host /bin/sh -c \
7076
"cd \"$PWD\"; $exportCmd; source /etc/set-environment; exec $cmd"

0 commit comments

Comments
 (0)