Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hid-tmff2 in NixOS #71

Closed
RaySlash opened this issue Sep 8, 2023 · 4 comments
Closed

hid-tmff2 in NixOS #71

RaySlash opened this issue Sep 8, 2023 · 4 comments

Comments

@RaySlash
Copy link
Contributor

RaySlash commented Sep 8, 2023

In order to use this driver in NixOS, one would have to make a derivation for the module. I was going through the process and was able to successfully add it to NixOS. The following file is needed to use the module.
Module ( hid-tmff2.nix ) :

{ stdenv, lib, fetchFromGitHub, kernel }:

stdenv.mkDerivation {
	pname = "hid-tmff2";
	version = "unstable-2023-09-23";

	src = fetchFromGitHub {
		owner = "Kimplul";
		repo = "hid-tmff2";
		rev = "b2872a893afd0f9cd0bfd4644348f3b8645edbed";
		hash = "sha256-7AlBxFUqw0nFl9f03WWDhUQsd1RCdtvcUeVWfcO9J8Q=";
		fetchSubmodules = true;
	};

	nativeBuildInputs = kernel.moduleBuildDependencies; 

	makeFlags = kernel.makeFlags ++ [
		"KDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
	];

	installFlags = [
		"INSTALL_MOD_PATH=${placeholder "out"}"
	];
  
	postPatch = "sed -i '/depmod -A/d' Makefile";

	meta = with lib; {
		description = "A linux kernel module for Thrustmaster T300RS and T248";
		homepage = "https://github.com/Kimplul/hid-tmff2";
		license = licenses.gpl2Plus;
		maintainers = [ maintainers.rayslash ];
		platforms = platforms.linux;
	};
}

Add this to config to load the module ( configuration.nix ) :

{ config, pkgs, ... }:

let
    hid-tmff2 = config.boot.kernelPackages.callPackage ./hid-tmff2.nix {};
in
{
    boot.blacklistedKernelModules = [ "hid-thrustmaster" ];
    boot.extraModulePackages = [ hid-tmff2 ];
    boot.kernelModules = [ "hid-tmff2" ];
    # Use boot.kernelModules = [ hid-tmff2 ]; to enable the module. Then, the user can load it using:
    # $ sudo modprobe hid-tmff2
    # OR use "" to autoload the module at startup
# Rest of config
};

Reference: https://nixos.wiki/wiki/Linux_kernel
Linux kernel module for Thrustmaster T300RS and T248 wheels

I had been working around 3 days of my time to find this and sort this out (mostly because im a noob in NixOS). I hope the OP would add this information for NixOS users in the Wiki or someone can find this Issue to use this.

EDIT: I have opened a PR on nixpkgs for hid-tmff2. [MERGED]

@Kimplul
Copy link
Owner

Kimplul commented Sep 8, 2023

Hello, thanks a lot, greatly appreciated. I'd be happy to add a page to the wiki outlining integration into different distros.
I think there are some other distros that require drivers to be wrapped in packages/modules/whatever the terminology is, could be useful to have a list of them.

I really only use Debian myself and I don't think I can promise to keep integration stuff up to date, but as long as people open up issues whenever something goes out of date I don't see much of an issue with the idea.

Just checking, but what do you mean that the rebuild crashes with error if depmod -A is executed? It was initially added because in some situations the kernel wouldn't immediately probe a newly installed module. Do you know if NixOS automatically refreshes/rescans kernel modules on install or is there a risk that the behaviour might show up again?

@RaySlash
Copy link
Contributor Author

RaySlash commented Sep 8, 2023

NixOS handles depmod differently. It actually does it when the final set of modules are assembled. This would mean, it is something only needed for NixOS afaik. I was having an error such as the one below earlier without that change I made:

building Nix...
building the system configuration...
these 8 derivations will be built:
  /nix/store/xsq3h167wim46y23crky95s5j5nj9mc7-hid-tmff2-6.1.51.drv
  /nix/store/2sl2afffcjvqv5f9nhc9j5cbgxd05sm0-kernel-modules.drv
  /nix/store/4bbsf4jajjcpxgrfsz8ysfzcw315bgis-linux-6.1.51-modules.drv
  /nix/store/7zpxihzvlhr0zvc6vs37gmdd25krsgay-linux-6.1.51-modules-shrunk.drv
  /nix/store/sxvgk3wg0b5wnmd9gqi1qp1s5q649yjx-stage-1-init.sh.drv
  /nix/store/j2szwpvy2bbcajhc46wc2d985y207f12-initrd-linux-6.1.51.drv
  /nix/store/mwcx67bcxym09dfcwvmc9nksdwg5pn0v-boot.json.drv
  /nix/store/njplhrxcp0z4xdl3xz9l30qnimy95q2h-nixos-system-frost-23.11pre521611.e56990880811.drv
building '/nix/store/xsq3h167wim46y23crky95s5j5nj9mc7-hid-tmff2-6.1.51.drv'...
unpacking sources
unpacking source archive /nix/store/y5s2incxwz9vx5hdymvhpc49k0gx5pm1-source
source root is source
patching sources
updateAutotoolsGnuConfigScriptsPhase
configuring
no configure script, doing nothing
building
build flags: SHELL=/nix/store/r4vxljid3iq94jp7qvd639sps0fscwy3-bash-5.2-p15/bin/bash O=\$\(buildRoot\) CC=/nix/store/civqmfc14c8x7l59nfiwb3qggr8sghrg-gcc-wrapper-12.3.0/bin/cc HOSTCC=/nix/store/civqmfc14c8x7l59nfiwb3qggr8sghrg-gcc-wrapper-12.3.0/bin/cc HOSTLD=/nix/store/cyb4bb44krf4ghw8qasa03sxi2k4g6a4-binutils-wrapper-2.40/bin/ld ARCH=x86_64 KDIR=/nix/store/paa5039bzjz3afd451qah4bm3cx73a2l-linux-6.1.51-dev/lib/modules/6.1.51/build
make -C hid-tminit KDIR="/nix/store/paa5039bzjz3afd451qah4bm3cx73a2l-linux-6.1.51-dev/lib/modules/6.1.51/build"
make[1]: Entering directory '/build/source/hid-tminit'
make -C /nix/store/paa5039bzjz3afd451qah4bm3cx73a2l-linux-6.1.51-dev/lib/modules/6.1.51/build M=/build/source/hid-tminit modules
  CC [M]  /build/source/hid-tminit/hid-tminit.o
  MODPOST /build/source/hid-tminit/Module.symvers
  CC [M]  /build/source/hid-tminit/hid-tminit.mod.o
  LD [M]  /build/source/hid-tminit/hid-tminit.ko
  BTF [M] /build/source/hid-tminit/hid-tminit.ko
Skipping BTF generation for /build/source/hid-tminit/hid-tminit.ko due to unavailability of vmlinux
make[1]: Leaving directory '/build/source/hid-tminit'
make -C /nix/store/paa5039bzjz3afd451qah4bm3cx73a2l-linux-6.1.51-dev/lib/modules/6.1.51/build M=/build/source modules
  CC [M]  /build/source/hid-tmff2.o
  CC [M]  /build/source/hid-tmt300rs.o
  CC [M]  /build/source/hid-tmt248.o
  CC [M]  /build/source/hid-tmtx.o
  LD [M]  /build/source/hid-tmff-new.o
  MODPOST /build/source/Module.symvers
  CC [M]  /build/source/hid-tmff-new.mod.o
  LD [M]  /build/source/hid-tmff-new.ko
  BTF [M] /build/source/hid-tmff-new.ko
Skipping BTF generation for /build/source/hid-tmff-new.ko due to unavailability of vmlinux
installing
install flags: SHELL=/nix/store/r4vxljid3iq94jp7qvd639sps0fscwy3-bash-5.2-p15/bin/bash O=\$\(buildRoot\) CC=/nix/store/civqmfc14c8x7l59nfiwb3qggr8sghrg-gcc-wrapper-12.3.0/bin/cc HOSTCC=/nix/store/civqmfc14c8x7l59nfiwb3qggr8sghrg-gcc-wrapper-12.3.0/bin/cc HOSTLD=/nix/store/cyb4bb44krf4ghw8qasa03sxi2k4g6a4-binutils-wrapper-2.40/bin/ld ARCH=x86_64 KDIR=/nix/store/paa5039bzjz3afd451qah4bm3cx73a2l-linux-6.1.51-dev/lib/modules/6.1.51/build INSTALL_MOD_PATH=/nix/store/d1c7blhiji1clxa33v9by0j7bgi0f6k1-hid-tmff2-6.1.51 install
make -C hid-tminit KDIR="/nix/store/paa5039bzjz3afd451qah4bm3cx73a2l-linux-6.1.51-dev/lib/modules/6.1.51/build" install
make[1]: Entering directory '/build/source/hid-tminit'
make -C /nix/store/paa5039bzjz3afd451qah4bm3cx73a2l-linux-6.1.51-dev/lib/modules/6.1.51/build M=/build/source/hid-tminit modules_install
  INSTALL /nix/store/d1c7blhiji1clxa33v9by0j7bgi0f6k1-hid-tmff2-6.1.51/lib/modules/6.1.51/extra/hid-tminit.ko
  XZ      /nix/store/d1c7blhiji1clxa33v9by0j7bgi0f6k1-hid-tmff2-6.1.51/lib/modules/6.1.51/extra/hid-tminit.ko.xz
  DEPMOD  /nix/store/d1c7blhiji1clxa33v9by0j7bgi0f6k1-hid-tmff2-6.1.51/lib/modules/6.1.51
Warning: modules_install: missing 'System.map' file. Skipping depmod.
make[1]: Leaving directory '/build/source/hid-tminit'
make -C /nix/store/paa5039bzjz3afd451qah4bm3cx73a2l-linux-6.1.51-dev/lib/modules/6.1.51/build M=/build/source modules_install
  INSTALL /nix/store/d1c7blhiji1clxa33v9by0j7bgi0f6k1-hid-tmff2-6.1.51/lib/modules/6.1.51/extra/hid-tmff-new.ko
  XZ      /nix/store/d1c7blhiji1clxa33v9by0j7bgi0f6k1-hid-tmff2-6.1.51/lib/modules/6.1.51/extra/hid-tmff-new.ko.xz
  DEPMOD  /nix/store/d1c7blhiji1clxa33v9by0j7bgi0f6k1-hid-tmff2-6.1.51/lib/modules/6.1.51
Warning: modules_install: missing 'System.map' file. Skipping depmod.
depmod -A
depmod: ERROR: could not open directory /lib/modules/6.1.51: No such file or directory
depmod: ERROR: could not open directory /lib/modules/6.1.51: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
make: *** [Makefile:8: install] Error 1
error: builder for '/nix/store/xsq3h167wim46y23crky95s5j5nj9mc7-hid-tmff2-6.1.51.drv' failed with exit code 2
error: 1 dependencies of derivation '/nix/store/2sl2afffcjvqv5f9nhc9j5cbgxd05sm0-kernel-modules.drv' failed to build
error: 1 dependencies of derivation '/nix/store/4bbsf4jajjcpxgrfsz8ysfzcw315bgis-linux-6.1.51-modules.drv' failed to build
error: 1 dependencies of derivation '/nix/store/njplhrxcp0z4xdl3xz9l30qnimy95q2h-nixos-system-frost-23.11pre521611.e56990880811.drv' failed to build

@Kimplul
Copy link
Owner

Kimplul commented Sep 10, 2023

I added a page to the wiki with a reference to this issue. For now I think referencing is the better option, if the information goes out of date I might copy things over and add some note about this issue being out of date. Good to know that NixOS handles the depmod automatically.

Thanks again, closing as completed.

@Kimplul Kimplul closed this as completed Sep 10, 2023
@RaySlash
Copy link
Contributor Author

RaySlash commented Sep 20, 2023

I have edited the derivation to use your repo and patch to remove the depmod lines so that it stays completely based of github/Kimplul/hid-tmff2. Any user that might want to use this might have to update the rev = "#commit-rev"; if they want a newer revision of the repo. Hopefully, ill try to update this to nixpkgs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants