Replies: 10 comments 3 replies
-
Compile yor kernelFollowing https://nixos.wiki/wiki/Kernel_Debugging_with_QEMU first hurdle seems
So taking the
# shell.nix
{ pkgs ? import <nixpkgs> {} }:
(pkgs.buildFHSUserEnv {
name = "linux-kernel-build";
targetPkgs = pkgs: (with pkgs; [
getopt
flex
bison
elfutils
binutils
ncurses.dev
openssl.dev
zlib.dev
gcc
gnumake
bc
]);
runScript = "bash";
}).env |
Beta Was this translation helpful? Give feedback.
-
You want to use https://nixos.wiki/wiki/Linux_kernel#Custom_configuration when building kernels inside of nixos but for that we would need to know the internal name of the options. I am not sure if we can then export the kernel and tell WSL to use it. |
Beta Was this translation helpful? Give feedback.
-
Regarding the @SuperSandro2000 where in the shell.nix would this Also asking because I rather enter shell.nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.stdenv.mkDerivation {
name = "linux-kernel-build";
nativeBuildInputs = with pkgs; [
getopt
flex
bison
gcc
gnumake
bc
pkg-config
binutils
];
buildInputs = with pkgs; [
elfutils
ncurses
openssl
zlib
];
} Also I noted that without kernel config with usbip on
|
Beta Was this translation helpful? Give feedback.
-
Following https://nixos.wiki/wiki/Linux_kernel#Booting_a_kernel_from_a_custom_source I now created this custom-kernel.nix: nix file
{ pkgs, ... }:
{
boot.kernelPackages = let
linux_wsl_pkg = { fetchurl, buildLinux, ... } @ args:
buildLinux (args // rec {
version = "5.10.102.1";
modDirVersion = version;
src = fetchurl {
url = "https://github.com/microsoft/WSL2-Linux-Kernel/tarball/linux-msft-wsl-${version}";
sha256 = "0000000000000000000000000000000000000000000000000000";
};
kernelPatches = [];
extraConfig = ''
CONFIG_USB_ACM y
CONFIG_USBIP_CORE y
CONFIG_USBIP_VHCI_HCD y
CONFIG_USBIP_VHCI_HC_PORTS 8
CONFIG_USBIP_VHCI_NR_HCS 1
CONFIG_USBIP_DEBUG y
CONFIG_USB_SERIAL y
'';
extraMeta.branch = "5.10";
} // (args.argsOverride or {}));
linux_wsl = pkgs.callPackage linux_wsl_pkg{};
in
pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor linux_wsl);
} |
Beta Was this translation helpful? Give feedback.
-
First I customized the kernel provided by WSL2 { pkgs ? import <nixpkgs> {} }:
pkgs.stdenv.mkDerivation rec {
name = "linux-kernel-build";
version = "5.10.102.1";
modDirVersion = version;
src = builtins.fetchTarball {
url = "https://github.com/microsoft/WSL2-Linux-Kernel/tarball/linux-msft-wsl-${version}";
sha256 = "18b5s6kxjnxnfhhh5ywgnxrj4pi8jr0g0bdd9y3vj7qi1q2nz7zw";
};
postUnpack = ''
(cd $sourceRoot
TOP=$(cat scripts/ld-version.sh|grep ^#\!.*bin|awk -F\ '{ print $1 }')
substituteInPlace scripts/ld-version.sh --replace "$TOP" "#!${pkgs.gawk}/bin/awk")
'';
nativeBuildInputs = with pkgs; [
getopt
flex
bison
gcc
gnumake
bc
pkg-config
binutils
];
buildInputs = with pkgs; [
elfutils
ncurses
openssl
zlib
];
}
Checked ( # default.nix
# borrowed here https://sourcegraph.com/github.com/tpwrules/nixos-m1/-/blob/nix/m1-support/kernel/package.nix
{ pkgs ? import <nixpkgs> {}}: let
localPkgs = import (pkgs.path) { system = builtins.currentSystem; };
readConfig = configfile: import (localPkgs.runCommand "config.nix" {} ''
echo "{" > "$out"
while IFS='=' read key val; do
[ "x''${key#CONFIG_}" != "x$key" ] || continue
no_firstquote="''${val#\"}";
echo ' "'"$key"'" = "'"''${no_firstquote%\"}"'";' >> "$out"
done < "${configfile}"
echo "}" >> $out
'').outPath;
linux_wsl_pkg = { stdenv, lib, fetchurl, fetchFromGitHub, fetchpatch, linuxKernel, ... } @ args:
linuxKernel.manualConfig rec {
inherit stdenv lib;
version = "5.10.102.1";
modDirVersion = version;
src = builtins.fetchTarball {
url = "https://github.com/microsoft/WSL2-Linux-Kernel/tarball/linux-msft-wsl-${version}";
sha256 = "18b5s6kxjnxnfhhh5ywgnxrj4pi8jr0g0bdd9y3vj7qi1q2nz7zw";
};
kernelPatches = [];
configfile = ./source/build/config-wsl-usb;
config = readConfig configfile;
extraMeta.branch = "5.10";
} // (args.argsOverride or {});
linux_wsl = pkgs.callPackage linux_wsl_pkg{};
in pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor linux_wsl) With this I just get
I wonder how I disable
|
Beta Was this translation helpful? Give feedback.
-
Very very WIP my notes over here for anyone interested in this. The baseline for now is, I was not able to use the kernel built via nix in WSL2, my suspicion it has to do with the gcc version, so probably fixable. Other than that I was able to use something like this: environment.systemPackages = let inherit (pkgs.linuxPackages) usbip; in [
usbip
]; in my configuration.nix so once the rest (i. e. running a NixOS WSL instance as elevated windows user) is figured out one could use devices from inside nixos wsl instance. |
Beta Was this translation helpful? Give feedback.
-
Work to enhance the experience of usbip has started with PR #263 I have this working without issues, the handling of auto-mounting from within the WSL using systemd is a work-around of the issue of |
Beta Was this translation helpful? Give feedback.
-
I just had an issue with the |
Beta Was this translation helpful? Give feedback.
-
How do I make the |
Beta Was this translation helpful? Give feedback.
-
I have POC to build a custom kernel with import <nixpkgs> {};
{
kernel = let
tag = "5.15.146.1";
in pkgs.linuxPackagesFor (pkgs.linuxManualConfig rec {
version = "${tag}-wsl";
src = applyPatches {
src = pkgs.fetchFromGitHub {
owner = "microsoft";
repo = "WSL2-Linux-Kernel";
rev = "linux-msft-wsl-${tag}";
hash = "sha256-Ogce975l7yrca047+/nm+I5Bm8EMyzd+FdszzpAQ6NM=";
};
patches = [
./wsl-kernel.diff
];
};
allowImportFromDerivation = true;
configfile = "${src}/Microsoft/config-wsl";
modDirVersion = "${tag}-microsoft-standard-WSL2";
});
} then
my patch file is the following to fix nftables support diff --git a/arch/x86/configs/config-wsl b/arch/x86/configs/config-wsl
index 51935f9f2..365529760 100644
--- a/arch/x86/configs/config-wsl
+++ b/arch/x86/configs/config-wsl
@@ -1066,7 +1069,7 @@ CONFIG_NF_NAT_MASQUERADE=y
CONFIG_NETFILTER_SYNPROXY=y
CONFIG_NF_TABLES=y
CONFIG_NF_TABLES_INET=y
-# CONFIG_NF_TABLES_NETDEV is not set
+CONFIG_NF_TABLES_NETDEV=y
CONFIG_NFT_NUMGEN=y
CONFIG_NFT_CT=y
CONFIG_NFT_COUNTER=y
@@ -1084,11 +1087,18 @@ CONFIG_NFT_REJECT=y
CONFIG_NFT_REJECT_INET=y
CONFIG_NFT_COMPAT=y
# CONFIG_NFT_HASH is not set
+CONFIG_NFT_FIB=y
+CONFIG_NFT_FIB_INET=y
CONFIG_NFT_XFRM=y
CONFIG_NFT_SOCKET=y
# CONFIG_NFT_OSF is not set
# CONFIG_NFT_TPROXY is not set
# CONFIG_NFT_SYNPROXY is not set
+# CONFIG_NF_DUP_NETDEV is not set
+# CONFIG_NFT_DUP_NETDEV is not set
+# CONFIG_NFT_FWD_NETDEV is not set
+CONFIG_NFT_FIB_NETDEV=y
+# CONFIG_NFT_REJECT_NETDEV is not set
# CONFIG_NF_FLOW_TABLE is not set
CONFIG_NETFILTER_XTABLES=y
# CONFIG_NETFILTER_XTABLES_COMPAT is not set
@@ -1256,7 +1266,7 @@ CONFIG_NF_SOCKET_IPV4=y
CONFIG_NF_TABLES_IPV4=y
CONFIG_NFT_REJECT_IPV4=y
# CONFIG_NFT_DUP_IPV4 is not set
-# CONFIG_NFT_FIB_IPV4 is not set
+CONFIG_NFT_FIB_IPV4=y
# CONFIG_NF_TABLES_ARP is not set
# CONFIG_NF_DUP_IPV4 is not set
# CONFIG_NF_LOG_ARP is not set
@@ -1295,7 +1305,7 @@ CONFIG_NF_SOCKET_IPV6=y
CONFIG_NF_TABLES_IPV6=y
CONFIG_NFT_REJECT_IPV6=y
# CONFIG_NFT_DUP_IPV6 is not set
-# CONFIG_NFT_FIB_IPV6 is not set
+CONFIG_NFT_FIB_IPV6=y
# CONFIG_NF_DUP_IPV6 is not set
CONFIG_NF_REJECT_IPV6=y
CONFIG_NF_LOG_IPV6=y I probably turn this eventually into something more accessible for NixOS-WSL |
Beta Was this translation helpful? Give feedback.
-
This discussion was converted to an issue. Please see the continued thread here: #111
It would be awesome to have usbip support in NixOS-WSL (see https://github.com/dorssel/usbipd-win/wiki/WSL-support).
I've only gotten so far to try the usbip command inside the VM and I'm still not clear how to get that. Loading kernel package in configuration.nix didn't seem to as we use the kernel provided by Microsoft.
Is it just a case of building our own version of the MS kernel (https://nixos.wiki/wiki/Linux_kernel) ?
When from Powershell (regular user, Windows side) running
➜ & 'C:\Program Files\usbipd-win\usbipd.exe' wsl attach --busid 3-1
I'm just stuck in the
usbipd: error: WSL 'usbip' client not correctly installed. See https://github.com/dorssel/usbipd-win/wiki/WSL-support for the latest instructions.
What do you say ? Can we figure this out as a Step-By-Step list maybe just to complete the instructions (saying just "on other distros") over at https://github.com/dorssel/usbipd-win/wiki/WSL-support ?
Beta Was this translation helpful? Give feedback.
All reactions