djanatyn / ssbm-nix

Nix expressions for Super Smash Bros. Melee players.
31 stars 17 forks source link

Add a systemd service to enable gcc overclocking on boot #10

Closed ursi closed 3 years ago

ursi commented 3 years ago

This addresses #9

djanatyn commented 3 years ago

Hi @ursi, thanks for the PR and thanks for your patience! Just took a look this morning.

How does this behave differently from boot.kernelModules?:

boot.kernelModules = [ "yourmodulename" ];

I'm wondering if we might want to instead update our config to use existing NixOS infrastructure for loading kernel modules:

diff --git a/flake.nix b/flake.nix
index 1138e4a..5926745 100644
--- a/flake.nix
+++ b/flake.nix
@@ -71,6 +71,7 @@
       config = {
         nixpkgs.overlays = [ (mkIf cfg.overlay.enable self.overlay) ];
         services.udev.extraRules = mkIf cfg.gcc.rules.enable cfg.gcc.rules.rules;
+        boot.kernelModules = mkIf cfg.gcc.oc-kmod.enable ["gcadapter_oc"];
         boot.extraModulePackages = mkIf cfg.gcc.oc-kmod.enable [
           config.boot.kernelPackages.gcadapter-oc-kmod
         ];

https://github.com/NixOS/nixpkgs/blob/nixos-20.09/nixos/modules/system/boot/kernel.nix#L120

    boot.kernelModules = mkOption {
      type = types.listOf types.str;
      default = [];
      description = ''
        The set of kernel modules to be loaded in the second stage of
        the boot process.  Note that modules that are needed to
        mount the root file system should be added to
        <option>boot.initrd.availableKernelModules</option> or
        <option>boot.initrd.kernelModules</option>.
      '';
    };

I agree that we should notify users that they'll need to execute sudo modprobe gcadpter_oc. Here's a potential README.md change:

index 97cf4fe..db5cd46 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,20 @@ Goals:
 # Playing Slippi Online!
 Run `slippi-netplay` or the desktop entry.

+# FAQ
+## How do I enable the GCC overclock adapter?
+Enable the configuration option:
+``` nix
+ssbm.gcc.oc-kmod.enable = true;
+```
+
+After building that configuration and switching to it, load the module:
+``` sh
+sudo modprobe gcadpter_oc
+```
+
+The kernel module will be reloaded automatically on subsequent boots, since the flake updates `boot.kernelModules`.
+
 ## TODO
 ### Playing Melee
 * [X] [slippi-netplay](https://github.com/project-slippi/Ishiiruka/pull/164)

My understanding is that we wouldn't need this systemd unit after an initial boot, if we update boot.kernelModules in the flake. I think that's the best call here - what are your thoughts @ursi?

I might be misunderstanding some part of how this unit works - please let me know if so!

ursi commented 3 years ago

I didn't know about that option, those changes look good to me!

djanatyn commented 3 years ago

Pushed https://github.com/djanatyn/ssbm-nix/commit/8107028168777bdf91e13dff31f82cb64095a874.