This is a NixOS newbie question.
I would like to make some experimental changes to the Linux mlx4 module on my NixOS machine. I am looking for an edit-compile-run workflow where I would build and load (insmod) the module. It is important that this would happen directly on the host and not inside a VM.
Can anybody please tell me how to do this? I am hoping that I can do something like nix-build ... && insmod .../mlx4.ko but I am not sure how to connect those dots :).
nix-shell on the kernel package, run unpackPhase to unpack it, and then find the kernel config somewhere and build as usual, then edit+make+insmod in a loop, and once your changes are working, you can make an override against the kernel and supply a patch so nix can rereate the changes automaticaly
Here is what I have so far:
$ nix-shell -A linuxPackages.kernel
$ unpackPhase
$ cd linux-4.4.6/
$ echo $configurePhase
runHook preConfigure ln -sv /nix/store/6gg85hq4ccd2s1r9y6iyk61vblya8mw3-linux-config-4.4.6 $buildRoot/.config make $makeFlags "${makeFlagsArray[@]}" oldconfig runHook postConfigure # Note: we can get rid of this once http://permalink.gmane.org/gmane.linux.kbuild.devel/13800 is merged. buildFlagsArray+=("KBUILD_BUILD_TIMESTAMP=$(date -u -d @$SOURCE_DATE_EPOCH)")
$ exec $configurePhase
bash: exec: runHook: not found
If I manually run cp /nix/store/6gg85hq4ccd2s1r9y6iyk61vblya8mw3-linux-config-4.4.6 .config, I can then execute make.
Or to just build those modules:
make modules M=drivers/net/ethernet/mellanox/
sudo insmod drivers/net/ethernet/mellanox//mlx4/mlx4_en.ko
However, I get an error:
insmod: ERROR: could not insert module drivers/net/ethernet/mellanox//mlx4/mlx4_en.ko: Invalid module format
And in dmesg:
[232201.652452] mlx4_en: no symbol version for module_layout
Aha, I'm also missing Module.symvers
Module.symvers comes from the kernel dev package. You need to do something like make -C ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build M=$(pwd)/drivers/net/ethernet/mellanox modules
Also no messing with .config should be needed with that.
Also, I didn't actually test the above ;)
Thanks for the tips!
I've pushed some documentation on this for future me: 2d6d731f246fa93ce89cac8bd4c78f45c15a38fe