00Asgaroth00 / dotfiles

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dotfiles

dotfiles for use with home directories on Linux or Windows WSL2

Requirements

Windows

  • Install Scoop inside powershell session


> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
> Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression

  • Install helper tools via scoop in command/powershell prompt


> scoop install curl wget wslinternals

WSL

  • Ensure WSL2 is installed

  • Start with basic .wslconfig file, edit/add into %UserProfile/.wslconfig


[wsl2]
memory=8GB
processors=4
swap=0
guiApplications=false
kernelCommandLine = cgroup_no_v1=all
# networkingMode = bridged
# vmSwitch = External-Bridge


> wget https://images.linuxcontainers.org/images/archlinux/current/amd64/default/20240318_04:18/rootfs.tar.xz -O d:\Temp\archlinux_rootfs.tar.xz

  • Import the image into WSL2 environment


> wsl.exe --import ArchTest c:\WSL\ArchTest d:\Temp\archlinux_rootfs.tar.xz

  • Start WSL image and configure your user (replace instances of <username> with your username)

    • > denotes a powershell promp

    • # denotes a wsl shell prompt


> wsl.exe -d ArchTest -u root
# pacman-key --init
# pacman-key --populate
# pacman-key --refresh-keys
# pacman -Sy archlinux-keyring
# pacman -Syyu
# pacman -S git zsh neovim
# groupadd sudo
# sed -i.bak -e 's|^# \(%wheel.*NOPASSWD.*\)|\1|g' -e 's|^# \(%sudo.*ALL\)|\1|g' /etc/sudoers
# useradd -m -G wheel,sudo -s /bin/zsh <username>
# passwd <username>
# cat << __EOFL__ >> /etc/fstab
cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate 0 0
__EOFL__
# cat << __EOFL__ > /etc/wsl.conf
[boot]
systemd=true

[automount]
enabled = true
options = "metadata,umask=0022,fmask=0011,dmask=0022"
mountFsTab = true

[mount]
uid = 1000
gid = 1000
umask = 0022
fmask = 0011
dmask = 0022

[user]
default = "<username>"

[network]
hostname = archtest
generateHosts = true
generateResolvConf = true

[interop]
enabled = true
appendWindowsPath = true
__EOFL__

# exit
> wsl --shutdown
> wsl -d ArchTest --cd ~
# git clone https://github.com/00Asgaroth00/dotfiles.git

NIX in WSL

  • Install nix package manager


# sudo pacman -S nix

  • Amend the nix main configuration file /etc/nix/nix.conf


# sudo cp ~/dotfiles/etc/nix/nix.conf /etc/nix/nix.conf

  • Specify a temp directory for the nix daemon to use, this is a workaround for when /tmp is too small and you run out of space when trying to install/build new packages, specify a path with sufficient space.


# sudo mkdir /etc/systemd/system/nix-daemon.service.d
# sudo cp ~/dotfiles/etc/systemd/system/nix-daemon.service.d/override.conf /etc/systemd/system/nix-daemon.service.d/.
# sudo mkdir /var/tmp/nix-daemon

  • Add your user to the nix group to use the nix daemon


# sudo usermod -aG nix-users <username>

  • Restart the nix daemon service


# sudo systemctl daemon-reload
# sudo systemctl restart nix-daemon
# sudo systemctl status nix-daemon
# sudo systemctl enable nix-daemon

  • Logout of WSL environment and log back in to activate group modifications


# exit
> wsl -d ArchTest --cd ~

  • Configure the nix packages channel (using the "unstable" branch here)


# nix-channel --add https://nixos.org/channels/nixpkgs-unstable
# nix-channel --update

Build Home

  • Generate home configuration


# nix-shell -p home-manager
[nix-shell] home-manager switch --flake ~/dotfiles/home-manager/#$(id -un)
[nix-shell] exit
# exit
> alacritty --config-file alacritty-archtest.toml

Extras

Windows additions

  • Common apps I use in windows (some wrapped within yazi)


> scoop install mpv vlc irfanview imageglass wezterm alacritty

  • Setup ssh-agent forwarding between keepassxc/windows ssh-agent/wsl

    • Install needed tools


> scoop install npiperelay


> Remove-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
## REBOOT HERE
> Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
> winget install Microsoft.OpenSSH.Beta --override ADDLOCAL=Client
> Start-Service ssh-agent
> Set-Service ssh-agent -StartupType Automatic
> Get-Service ssh-agent

# rm $SSH_AUTH_SOCK
# (setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork &)

  • In windows enable the ssh agent in KeypassXC and load your keys.

  • In WSL see if you can see the keys being presented to the agent


# ssh-add -L


Docker

  • Install and enable docker daemon


# sudo pacman -S docker docker-buildx docker-compose
# sudo systemctl enable docker
# sudo usermod -aG docker <username>

GPU Hardware Acceleration


# sudo pacman -S mesa libva-mesa-driver libva-utils mesa-utils
# sudo usermod -aG video <username>
# export LIBVA_DRIVER_NAME=d3d12
# vainfo --display drm --device /dev/dri/card0
# glxinfo -B

Troubleshooting

  • Intermittently the users run directory /run/user/1000 is not created after the initial start of wsl after the installation/creation of the user process. A stop/start of the wsl environment usually corrects this.

  • Intermittently the X11 display is not linked correctly when wslg is enabled, we need to recreate the symbolic link

    • A more complete example gist can be seen here


# ln -s /mnt/wslg/.X11-unix/X0 /tmp/.X11-unix/

About


Languages

Language:Roff 82.7%Language:Nix 12.2%Language:Shell 3.6%Language:Lua 1.4%Language:Vim Script 0.1%