Skip to content

Commit

Permalink
Merge pull request #79 from nzbr/mount-fix
Browse files Browse the repository at this point in the history
Fix Windows File Systems not being mounted on first start when using the Installer
  • Loading branch information
nzbr authored Apr 17, 2022
2 parents f0dd180 + 67b9d7c commit c4b7e5f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions modules/installer.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ with builtins; with lib; {

contents = [
{ source = config.environment.etc."wsl.conf".source; target = "/etc/wsl.conf"; }
{ source = config.environment.etc."fstab".source; target = "/etc/fstab"; }
{ source = passwd; target = "/etc/passwd"; }
{ source = "${pkgs.busybox}/bin/busybox"; target = "/bin/sh"; }
{ source = "${pkgs.busybox}/bin/busybox"; target = "/bin/mount"; }
];
};

Expand Down
2 changes: 1 addition & 1 deletion modules/wsl-distro.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ with builtins; with lib;
config =
let
cfg = config.wsl;
syschdemd = import ../syschdemd.nix { inherit lib pkgs config; defaultUser = cfg.defaultUser; };
syschdemd = import ../syschdemd.nix { inherit lib pkgs config; defaultUser = cfg.defaultUser; defaultUserHome = config.users.users.${cfg.defaultUser}.home; };
in
mkIf cfg.enable {

Expand Down
10 changes: 8 additions & 2 deletions syschdemd.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{ lib, pkgs, config, defaultUser, ... }:
{ lib
, pkgs
, config
, defaultUser
, defaultUserHome ? "/home/${defaultUser}"
, ...
}:

pkgs.substituteAll {
name = "syschdemd";
Expand All @@ -8,8 +14,8 @@ pkgs.substituteAll {

buildInputs = with pkgs; [ daemonize ];

inherit defaultUser defaultUserHome;
inherit (pkgs) daemonize;
inherit defaultUser;
inherit (config.security) wrapperDir;
fsPackagesPath = lib.makeBinPath config.system.fsPackages;

Expand Down
8 changes: 7 additions & 1 deletion syschdemd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fi
# Pass external environment but filter variables specific to root user.
exportCmd="$(export -p | $sw/grep -vE ' (HOME|LOGNAME|SHELL|USER)='); export WSLPATH=\"$PATH\"; export INSIDE_NAMESPACE=true"

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

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

# If we are currently in /root, this is probably because the directory that WSL was started is inaccessible
# cd to the user's home to prevent a warning about permission being denied on /root
if [[ $PWD == "/root" ]]; then
cd @defaultUserHome@
fi

exec $sw/nsenter -t $(</run/systemd.pid) -p -m -- $sw/machinectl -q \
--uid=@defaultUser@ shell .host /bin/sh -c \
"cd \"$PWD\"; $exportCmd; source /etc/set-environment; exec $cmd"
Expand Down

0 comments on commit c4b7e5f

Please sign in to comment.