Search code examples
windows-subsystem-for-linuxnixos

Why nix-rebuild switch fails on nixos for WSL


to install nixos as A WSL distribution I followed these instructions:

https://github.com/nix-community/NixOS-WSL.

As they say : I download the latest release : https://github.com/nix-community/NixOS-WSL/releases/download/23.5.5.2/nixos-wsl.tar.gz

As they say I have updated the channel

Now I want to install git.

https://search.nixos.org/packages?channel=23.11&show=git&from=0&size=50&sort=relevance&type=packages&query=git

I followed these instructions: https://nixos.wiki/wiki/Nixos-rebuild

/etc/nixos/configuration.nix look like that now

# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page, on
# https://search.nixos.org/options and in the NixOS manual (`nixos-help`).

# NixOS-WSL specific options are documented on the NixOS-WSL repository:
# https://github.com/nix-community/NixOS-WSL

{ config, lib, pkgs, ... }:

{
  imports = [
    # include NixOS-WSL modules
    <nixos-wsl/modules>
  ];

  wsl.enable = true;
  wsl.defaultUser = "nixos";
  environment.systemPackages = [
    pkgs.git
  ];


  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It's perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
  system.stateVersion = "23.05"; # Did you read the comment?
}

After launching

 sudo nixos-rebuild switch

I get a very long error message.

warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos' does not exist, ignoring warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring error: file 'nixpkgs/nixos' was not found in the Nix search path (add it using $NIX_PATH or -I)

   at «string»:1:13:

        1| with import <nixpkgs/nixos> {}; config.system.build.nixos-rebuild
         |             ^ (use '--show-trace' to show detailed location information) building Nix... warning: Nix search path entry

'/nix/var/nix/profiles/per-user/root/channels/nixos' does not exist, ignoring warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring error: file 'nixpkgs/nixos' was not found in the Nix search path (add it using $NIX_PATH or -I)

   at «none»:0: (source not available) warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos' does not

exist, ignoring warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

   at «none»:0: (source not available) warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos' does not

exist, ignoring warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring error: file 'nixpkgs/nixos/modules/installer/tools/nix-fallback-paths.nix' was not found in the Nix search path (add it using $NIX_PATH or -I)

   at «none»:0: (source not available) /tmp/nixos-rebuild.CkQLrX/nix warning: Nix search path entry

'/nix/var/nix/profiles/per-user/root/channels/nixos' does not exist, ignoring warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

   at «none»:0: (source not available) building the system configuration... warning: Nix search path entry

'/nix/var/nix/profiles/per-user/root/channels/nixos' does not exist, ignoring warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring error: file 'nixpkgs/nixos' was not found in the Nix search path (add it using $NIX_PATH or -I)

   at «none»:0: (source not available)

Solution

  • Apparently the instructions in the README are lacking a bit. In NixOS-WSL issue tracker @mprasil was kind enough to share the missing step:

    sudo nix-channel --add  https://nixos.org/channels/nixos-23.11 nixos
    sudo nix-channel --update
    sudo nixos-rebuild switch