From 202e250cbf776f9270117c4be60f567505fd405f Mon Sep 17 00:00:00 2001 From: pegasust Date: Mon, 7 Nov 2022 10:15:12 +0000 Subject: [PATCH] some bash runbook to illustrate mounting errors on nixos-wsl --- home-nix/home.nix | 2 +- system-nix/configuration.nix | 2 +- system-nix/hardware-configuration.nix | 16 ++++++++-------- system-nix/scripts/felia-hwconf.sh | 8 ++++++++ system-nix/scripts/felia-mount.sh | 14 ++++++++++++++ system-nix/scripts/mount-windrive.sh | 11 +++++++++++ 6 files changed, 43 insertions(+), 10 deletions(-) create mode 100755 system-nix/scripts/felia-hwconf.sh create mode 100755 system-nix/scripts/felia-mount.sh create mode 100755 system-nix/scripts/mount-windrive.sh diff --git a/home-nix/home.nix b/home-nix/home.nix index b9e74ce..c07c578 100644 --- a/home-nix/home.nix +++ b/home-nix/home.nix @@ -20,7 +20,6 @@ }; programs.tmux = { enable = true; - shell = "zsh"; extraConfig = builtins.readFile ../tmux/.tmux.conf; }; programs.exa = { @@ -66,6 +65,7 @@ a="add"; c="commit"; ca="commit --ammend"; cm="commit -m"; lol="log --graph --decorate --pretty=oneline --abbrev-commit"; lola="log --graph --decorate --pretty=oneline --abbrev-commit --all"; + sts="status"; }; extraConfig = { merge = {tool="vimdiff"; conflictstyle="diff3";}; diff --git a/system-nix/configuration.nix b/system-nix/configuration.nix index 20bf068..f50ec80 100755 --- a/system-nix/configuration.nix +++ b/system-nix/configuration.nix @@ -18,7 +18,7 @@ in automountPath = "/mnt"; defaultUser = "nixos"; # if change defaultUser, make sure uid to be 1000 (first user) startMenuLaunchers = true; - + automountOptions = "drvfs,metadata,uid=1000,gid=100"; # Enable native Docker support # docker-native.enable = true; diff --git a/system-nix/hardware-configuration.nix b/system-nix/hardware-configuration.nix index bd15e46..13b220c 100644 --- a/system-nix/hardware-configuration.nix +++ b/system-nix/hardware-configuration.nix @@ -18,12 +18,12 @@ fileSystems."/usr/lib/wsl/drivers" = { device = "drivers"; - fsType = "9p"; + fsType = "drvfs"; }; fileSystems."/usr/lib/wsl/lib" = { device = "lib"; - fsType = "9p"; + fsType = "drvfs"; }; fileSystems."/mnt/wsl" = @@ -32,18 +32,18 @@ }; fileSystems."/mnt/c" = - { device = "C:\134"; - fsType = "9p"; + { device = "C:"; + fsType = "drvfs"; }; fileSystems."/mnt/d" = - { device = "D:\134"; - fsType = "9p"; + { device = "D:"; + fsType = "drvfs"; }; fileSystems."/mnt/f" = - { device = "F:\134"; - fsType = "9p"; + { device = "F:"; + fsType = "drvfs"; }; swapDevices = [ ]; diff --git a/system-nix/scripts/felia-hwconf.sh b/system-nix/scripts/felia-hwconf.sh new file mode 100755 index 0000000..4e108dd --- /dev/null +++ b/system-nix/scripts/felia-hwconf.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh +# This is used when we need to refresh hardware-configuration.nix +# Basically what this does is to mount the drives, then ask nixos-generate-config +# to regenerate hardware-configuration.nix for us. +# Manual on nixos-generate-config [here](https://www.mankier.com/8/nixos-generate-config) +SCRIPT_DIR=$(realpath $(dirname $0)) +${SCRIPT_DIR}/felia-mount.sh +sudo nixos-generate-config diff --git a/system-nix/scripts/felia-mount.sh b/system-nix/scripts/felia-mount.sh new file mode 100755 index 0000000..1900fe8 --- /dev/null +++ b/system-nix/scripts/felia-mount.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh +SCRIPT_DIR=$(realpath $(dirname $0)) + +function mntDrive() { + WSL_DRIVE=$(echo $1 | tr '[:upper:]' '[:lower:]') + ${SCRIPT_DIR}/mount-windrive.sh $1 $WSL_DRIVE + echo "ls /mnt/${WSL_DRIVE}" + ls /mnt/${WSL_DRIVE} +} + +mntDrive C +mntDrive D +mntDrive F + diff --git a/system-nix/scripts/mount-windrive.sh b/system-nix/scripts/mount-windrive.sh new file mode 100755 index 0000000..fdde18c --- /dev/null +++ b/system-nix/scripts/mount-windrive.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +# https://linuxnightly.com/mount-and-access-hard-drives-in-windows-subsystem-for-linux-wsl/ +# Usage: scripts/mount-windrive.sh C # /mnt/c -> C:\ + +WIN_DRIVE_CHAR=${1:-"C"} +WSL_DRIVE_CHAR=${2:-$(echo $WIN_DRIVE_CHAR | tr '[:upper:]' '[:lower:]')} + +sudo umount "/mnt/${WSL_DRIVE_CHAR}" +sudo mount -t drvfs "${WIN_DRIVE_CHAR}:" "/mnt/${WSL_DRIVE_CHAR}" +