wls2安装nixos

# 安装最新的wsl,最新的支持systemd
# https://github.com/microsoft/WSL/releases/

# 下载nixos的wsl镜像 https://github.com/nix-community/NixOS-WSL/releases
wsl --import NixOS .\NixOS\ nixos-wsl-installer.tar.gz --version 2
  • 常见命令

# 系统列表
wsl --list
# 进入os
wsl -d NixOS
# 设为默认
wsl -s NixOS


# 设置没人wsl2
wsl --set-default-version 2

# 查看当前版本
wsl -l -v
# 卸载
wsl --unregister NixOS
  • 编辑配置开启docker

nano /etc/nixos/configuration.nix

# 在wsl里面操作数据
wsl = {
    # Enable native Docker support
    docker-native.enable = true;
}

# 配置允许其他源用户
nix.settings.trusted-users=["root" "jcleng" "nixos"];
# 构建的时候就可使用: --option substituters "https://mirror.nju.edu.cn/nix-channels/store/"
# https://mirror.sjtu.edu.cn/nix-channels/store

# 安装软件
environment.systemPackages = with pkgs; [
   wget
   k3s
   tmux
   vim
   git
];
  • ArchWSL2

https://github.com/yuk7/ArchWSL/releases
# 下载 Arch.zip ,解压,运行Arch.exe首次安装,安装完成之后直接进入Arch.exe
# systemd支持,默认已经安装
# https://github.com/arkane-systems/genie/releases/tag/v2.5
pacman -U genie-systemd-2.5-amd64.tar.gz

# 修改源
nano /etc/pacman.d/mirrorlist
Server = https://mirrors.aliyun.com/archlinux/$repo/os/$arch

pacman -Syy
pacman -S archlinux-keyring
pacman -S docker docker-compose
systemctl start docker
docker ps
  • 给nixos启用code-server

# Experimental support for VS Code Server in NixOS. The NodeJS by default supplied by VS Code cannot be used within NixOS due to missing hardcoded paths, so it is automatically replaced by a symlink to a compatible version of NodeJS that does work under NixOS.


# https://github.com/msteen/nixos-vscode-server
{
  imports = [
    (fetchTarball "https://github.com/msteen/nixos-vscode-server/tarball/master")
  ];

  services.vscode-server.enable = true;
}


sudo nixos-rebuild switch --option substituters http://cache.leng2011.icu
# 服务自启和启动
systemctl --user enable auto-fix-vscode-server.service
systemctl --user start auto-fix-vscode-server.service

# 使用,在nixos里面运行命令即可
code .
  • 桌面

# 默认已经支持x11的
ls /tmp/.X11-unix
# X0

# 或者配合手动运行vnc服务

# 如果安装了KDE
startplasma-x11
# 离线下载的地址wsl2的镜像差不多500m,小于的就是wsl1的镜像
https://learn.microsoft.com/en-us/windows/wsl/install-manual#downloading-distributions

# 点击安装
Ubuntu2204-221101.AppxBundle
# 或者手动命令powershell安装操作
Import-Module Appx
Add-AppxPackage .\Ubuntu2204-221101.AppxBundle

# 程序就会安装,如果启动不了,手动进行安装
# 在C:\Program Files\WindowsApps目录查找带有名字的文件夹,比如:CanonicalGroupLimited.Ubuntu_2204.1.8.0_x64__79rhkp1fndgsc
# 进入,安装到本目录的ubuntu21文件夹下
# 复制install.tar.gz到指定目录
wsl --import ubuntu21 .\ubuntu21 .\install.tar.gz
wsl -l -v

# 手动启动,-u指定状态
wsl -d ubuntu21 -u jcleng
# 删除
wsl --unregister ubuntu21

# 源 /etc/apt/sources.list
apt update
apt install -y docker docker.io wget curl git tree