summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornzbr <mail@nzbr.de>2022-04-17 18:21:28 +0200
committerGitHub <noreply@github.com>2022-04-17 18:21:28 +0200
commitc4b7e5f11dfde3cbc6e53c17fd4534db4b8cd69d (patch)
tree8e74d69e0b3a42e44642ae29408249d0bf40e6a0
parentf0dd180c37bff372f446f7ae89e385c4d6c49e09 (diff)
parent67b9d7c14322667e2a30405edcc812164b73738f (diff)
Merge pull request #79 from nzbr/mount-fix
Fix Windows File Systems not being mounted on first start when using the Installer
-rw-r--r--modules/installer.nix3
-rw-r--r--modules/wsl-distro.nix2
-rw-r--r--syschdemd.nix10
-rw-r--r--syschdemd.sh8
4 files changed, 19 insertions, 4 deletions
diff --git a/modules/installer.nix b/modules/installer.nix
index 739adf3..04d5127 100644
--- a/modules/installer.nix
+++ b/modules/installer.nix
@@ -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"; }
];
};
diff --git a/modules/wsl-distro.nix b/modules/wsl-distro.nix
index a2d7145..1a81db5 100644
--- a/modules/wsl-distro.nix
+++ b/modules/wsl-distro.nix
@@ -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 {
diff --git a/syschdemd.nix b/syschdemd.nix
index 894f1bd..051702e 100644
--- a/syschdemd.nix
+++ b/syschdemd.nix
@@ -1,4 +1,10 @@
-{ lib, pkgs, config, defaultUser, ... }:
+{ lib
+, pkgs
+, config
+, defaultUser
+, defaultUserHome ? "/home/${defaultUser}"
+, ...
+}:
pkgs.substituteAll {
name = "syschdemd";
@@ -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;
diff --git a/syschdemd.sh b/syschdemd.sh
index 3b2cb59..418d920 100644
--- a/syschdemd.sh
+++ b/syschdemd.sh
@@ -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
@@ -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"