Guides
WSL2 & Nix Integration Troubleshooting Guide
Metadata
- Type: How-To Guide / Reference
- Audience: Intermediate / Advanced
- Prerequisites: Basic familiarity with command line, WSL2, and Nix package manager
Content
A comprehensive troubleshooting guide for WSL2 edge cases, Nix integration issues, and recovery procedures for failed installations.
Table of Contents
- WSL2 Edge Cases
- Nix Integration Issues
- Recovery Procedures
- Performance Optimization
- Cross-Platform Migration
- Emergency Recovery
WSL2 Edge Cases
Filesystem Issues
Problem: Symlinks fail to work between Windows and WSL2
# Check if symlinks are enabled
# Look for broken symlinks (red entries)
Root Cause: Windows filesystem doesn't support Unix symlinks by default.
Solutions:
-
Enable Developer Mode (Windows 10/11):
# Run in PowerShell as Administrator dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart -
Use WSL2 native filesystem:
# Move dotfiles to WSL2 filesystem -
Configure Git for WSL2:
Problem: Slow filesystem performance on Windows drives
# Test filesystem performance
Solution: Always work within WSL2 filesystem (~/) for performance-critical operations.
Problem: Permission denied errors on mounted Windows drives
# Check mount options
|
Solution: Remount with proper permissions:
# Create /etc/wsl.conf
# Restart WSL2 from Windows PowerShell
Networking Issues
Problem: DNS resolution fails in WSL2
# Test DNS resolution
Solutions:
-
Reset WSL2 DNS:
-
Configure permanent DNS:
[network] generateResolvConf = false EOF
sudo tee /etc/resolv.conf > /dev/null <<EOF nameserver 1.1.1.1 nameserver 8.8.8.8 EOF
#### Problem: Port forwarding doesn't work
```bash
# Check if port is bound
netstat -tulpn | grep :3000
Solution: Use Windows port proxy:
# Run in PowerShell as Administrator
netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=172.x.x.x
Memory and Resource Issues
Problem: WSL2 consumes excessive memory
# Check WSL2 memory usage
|
Solution: Limit WSL2 memory usage:
# Create %UserProfile%\.wslconfig
[wsl2]
memory=8GB
processors=4
swap=2GB
Problem: WSL2 doesn't release memory back to Windows
Solution: Compact WSL2 virtual disk:
# Run in PowerShell as Administrator
wsl --shutdown
diskpart
# select vdisk file="C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\ext4.vhdx"
# attach vdisk readonly
# compact vdisk
# detach vdisk
# exit
Nix Integration Issues
Installation Problems
Problem: Nix installation fails on WSL2
# Check if installation attempted
Solutions:
-
Use deterministic installer:
| -
Fix permissions after installation:
-
Enable systemd for Nix daemon (WSL2 Ubuntu 22.04+):
[boot] systemd=true EOF
#### Problem: Nix flakes not recognized
```bash
# Test flakes support
nix flake --help
Solution: Enable experimental features:
# Or globally
Problem: SSL certificate errors during Nix operations
# Test Nix store access
Solutions:
-
Update CA certificates:
&& -
Configure Nix with custom CA bundle:
Flake and Profile Issues
Problem: Flake lock file conflicts
# Check flake lock status
Solution: Update and rebuild lock file:
Problem: Nix profile conflicts with system packages
# List Nix profiles
# Check which packages are shadowing system ones
Solutions:
-
Remove conflicting profiles:
-
Use priority settings:
-
Create isolated development environments:
Problem: Nix store corruption
# Check store integrity
Solution: Repair corrupted store:
# Stop Nix daemon
# Repair store
# Restart daemon
Build and Cache Issues
Problem: Binary cache not working
# Test cache connectivity
Solution: Configure trusted substituters:
Problem: Out of disk space during build
# Check Nix store size
Solution: Clean up Nix store:
# Remove unused packages
# Deep cleanup (removes old generations)
# Optimize store (hard link identical files)
Recovery Procedures
Complete System Recovery
Scenario: Dotfiles installation completely broken
# 1. Backup current state
# 2. Reset to minimal shell
# 3. Clean chezmoi state
# 4. Reinstall from scratch
# Download and SHA256-verify the release installer per docs/guides/INSTALL.md.
Scenario: WSL2 completely broken
# From Windows PowerShell as Administrator
# 1. Export current installation (backup)
wsl --export Ubuntu Ubuntu-backup.tar
# 2. Unregister broken installation
wsl --unregister Ubuntu
# 3. Reinstall from Microsoft Store or import backup
wsl --import Ubuntu C:\WSL\Ubuntu Ubuntu-backup.tar
# 4. Reinstall dotfiles
# First copy the release-pinned, SHA256-verified installer into the distro.
wsl -d Ubuntu -u root -- bash /tmp/dotfiles-install.sh
Partial Recovery
Fix broken Nix installation
# 1. Remove broken Nix
||
||
# 2. Clean environment
# 3. Reinstall Nix
|
# 4. Restart shell and test
Fix broken shell configuration
# 1. Use emergency shell config
# 2. Test emergency config
# 3. Gradually restore
# 4. Reinstall dotfiles piece by piece
Data Recovery
Recover encrypted secrets
# 1. Check if key file exists
# 2. If missing, try to recover from backup locations
# 3. Test key validity
# 4. If key is lost, regenerate encrypted files
Recover Git configuration
# 1. Check current git config
# 2. Backup current config
# 3. Restore from dotfiles
# 4. Verify critical settings
Performance Optimization
WSL2 Performance Tuning
Optimize filesystem performance
# 1. Move frequently accessed files to WSL2 filesystem
# 2. Configure Git for performance
# 3. Use native WSL2 paths in tools
Reduce memory usage
# 1. Limit shell history
# 2. Disable unnecessary services
||
||
# 3. Configure swap usage
|
Nix Performance Tuning
Optimize Nix builds
# Configure build settings
Enable build caching
# Install and configure cachix
# Add to shell config
Cross-Platform Migration
Moving from macOS to WSL2
Environment differences checklist
# 1. Check path differences
| |
# 2. Check shell differences
# 3. Check package managers
&&
&&
&&
Migration procedure
# 1. Export current configuration
|
# 2. Transfer to WSL2 (from Windows side)
# Copy dotfiles-backup.tar.gz to Windows, then:
# cp /mnt/c/Users/username/Downloads/dotfiles-backup.tar.gz ./
# 3. Import on WSL2
# 4. Platform-specific adjustments
Moving from Linux to WSL2
Handle systemd differences
# Check systemd status
||
# Alternative service management for WSL2
Network configuration migration
# 1. Export network settings from source system
# 2. Adapt for WSL2
# (WSL2 handles most networking automatically)
Emergency Recovery
Emergency Shell Access
If shell is completely broken
# 1. Access via different shell
# 2. Or use emergency profile
# 3. Fix basic functionality
If WSL2 won't start
# From Windows PowerShell as Administrator
# 1. Check WSL2 status
wsl --status
# 2. Restart WSL2 service
net stop LxssManager
net start LxssManager
# 3. If that fails, restart Docker Desktop (if installed)
# Then restart WSL2
# 4. Last resort: restart Windows
Emergency Contacts and Resources
Diagnostic commands for support requests
# System information
||
# Nix information
||
||
# Dotfiles information
&&
||
# Generate diagnostic report
Support channels
- GitHub Issues: Repository Issues
- WSL2 Documentation: Microsoft WSL Docs
- Nix Documentation: Nix Manual
- Community Support: Stack Overflow, NixOS Discourse
Quick Reference
Essential Commands
# System status
# Quick fixes
# Emergency access
# Minimal PATH
Recovery Commands
# Nuclear options (use with caution)
This guide covers the most common WSL2 and Nix edge cases. For issues not covered here, refer to the specific tool documentation or create a support request with the diagnostic information provided.
Validation Checklist
Before reporting issues, verify your environment with these commands:
# WSL2 Environment Check
| ||
| |
# Nix Installation Check
&& ||
||
# Dotfiles Status Check
&& ||
&& ||
||
# Performance Check
|| |
Run this checklist and include the output when requesting support.