If you have WSL version 2.4.4 or later installed, you can open (double-click) the .wsl file to install it. It is also possible to perform the installation from a PowerShell:
1
wsl --install --from-file nixos.wsl
nixos.wsl must be the path to the file you just downloaded if you’re running the command in another directory.
You can use the --name and --location flags to change the name the distro is registered under (default: NixOS) and the location of the disk image (default: %localappdata%\wsl\{some random GUID}). For a full list of options, refer to wsl --help
To open a shell in your NixOS environment, run wsl -d NixOS, select NixOS from the profile dropdown in Windows Terminal or run it from your Start Menu. (Adjust the name accordingly if you changed it)
The VSCode Remote server can not be run as-is on NixOS, because it downloads a nodejs binary that requires /lib64/ld-linux-x86-64.so.2 to be present, which isn’t the case on NixOS.
There are two options to get the server to run. Option 1 is more robust but might impact other programs. Option 2 is a little bit more brittle and sometimes breaks on updates but doesn’t influence other programs. Both options require wget to be installed:
1 2 3
environment.systemPackages = [ pkgs.wget ];
Option 1: Set up nix-ld
nix-ld is a program that provides /lib64/ld-linux-x86-64.so.2, allowing foreign binaries to run on NixOS.
To set it up, add the following to your configuration:
Instead of using the Nix profile /nix/var/nix/profiles/system to keep track of the current and previous system configurations, use /nix/var/nix/profiles/system-profiles/name. When you use GRUB 2, for every system profile created with this flag, NixOS will create a submenu named “NixOS - Profile 'name'” in GRUB’s boot menu, containing the current and previous configurations of this profile.
For instance, if you want to test a configuration file named test.nix without affecting the default system profile, you would do:
$ nixos-rebuild switch -p test -I nixos-config=./test.nix
The new configuration will appear in the GRUB 2 submenu “NixOS - Profile 'test'”.
hardware.bluetooth.enable = true; # enables support for Bluetooth hardware.bluetooth.powerOnBoot = true; # powers up the default Bluetooth controller on boot
启用系统级工具
1 2 3 4 5 6 7 8 9 10 11 12 13
environment.systemPackages = with pkgs; [ vim wget pkgs.git pkgs.nodejs_20 pkgs.texliveSmall cpkgs.hexo-cli pkgs.pandoc pkgs.vscode pkgs.microsoft-edge pkgs.texliveSmall