fork/slippi-nix

git clone https://git.julia.blue/fork/slippi-nix

Daniel FlanaganAdd integration test61d6e9d

fix-recursion
15.6 KiB450 linesraw
1{
2  inputs = {
3    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
4    git-hooks.url = "github:cachix/git-hooks.nix";
5    git-hooks.inputs.nixpkgs.follows = "nixpkgs";
6    home-manager.url = "github:nix-community/home-manager";
7    home-manager.inputs.nixpkgs.follows = "nixpkgs";
8  };
9
10  nixConfig = {
11    extra-substituters = [
12      "https://slippi-nix.cachix.org"
13    ];
14
15    extra-trusted-public-keys = [
16      "slippi-nix.cachix.org-1:2qnPHiOxTRpzgLEtx6K4kXq/ySDg7zHEJ58J6xNDvBo="
17    ];
18  };
19
20  outputs = {
21    nixpkgs,
22    git-hooks,
23    home-manager,
24    self,
25    ...
26  }: let
27    defaults = {
28      netplay = {
29        version = "3.4.2";
30        hash = "sha256-XSVEk3k7Eq55VtkFUD2biLYUt0bUKRh2PKIpWmdx5Uo=";
31      };
32      playback = {
33        version = "3.4.3";
34        hash = "sha256-QsvayemrIztHSVcFh0I1/SOCoO6EsSTItrRQgqTWvG4=";
35      };
36      launcher = {
37        version = "2.11.6";
38        hash = "sha256-pdBPCQ0GL7TFM5o48noc6Tovmeq+f2M3wpallems8aE=";
39      };
40    };
41
42    inherit (self) outputs;
43    forSystems = nixpkgs.lib.genAttrs [
44      # "aarch64-linux"
45      # "aarch64-darwin"
46      # "x86_64-darwin"
47      "x86_64-linux"
48    ];
49    pkgsFor = system: (import nixpkgs {inherit system;});
50    genPkgs = func: (forSystems (system: func (pkgsFor system)));
51  in {
52    overlays = {
53      default = outputs.overlays.slippi;
54
55      slippi = final: prev: {
56        inherit (outputs.packages.${final.system}.slippi) slippi-netplay slippi-playback slippi-launcher;
57      };
58    };
59
60    packages = genPkgs (pkgs: {
61      default = outputs.packages.${pkgs.system}.slippi-launcher;
62      slippi-netplay = pkgs.callPackage ({
63        stdenvNoCC,
64        appimageTools,
65        fetchzip,
66        version ? defaults.netplay.version,
67        hash ? defaults.netplay.hash,
68      }: let
69        pname = "Slippi_Online-x86_64.AppImage";
70        zip = fetchzip {
71          inherit hash;
72          url = "https://github.com/project-slippi/Ishiiruka/releases/download/v${version}/FM-Slippi-${version}-Linux.zip";
73          stripRoot = false;
74        };
75        src = "${zip}/Slippi_Online-x86_64.AppImage";
76      in
77        stdenvNoCC.mkDerivation {
78          inherit pname version;
79
80          src = appimageTools.wrapType2 {
81            inherit pname version src;
82            extraPkgs = pkgs: with pkgs; [curl zlib mpg123];
83
84            postInstall = ''
85              ls -la "$out"
86              wrapProgram $out/bin/${pname}-${version} \
87                --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}"
88            '';
89          };
90
91          installPhase = ''
92            runHook preInstall
93
94            mkdir -p "$out/bin"
95            cp -r "$src/bin" "$out"
96
97            runHook postInstall
98          '';
99        }) {};
100      slippi-playback = pkgs.callPackage ({
101        stdenvNoCC,
102        appimageTools,
103        fetchzip,
104        version ? defaults.playback.version,
105        hash ? defaults.playback.hash,
106      }: let
107        pname = "Slippi_Playback-x86_64.AppImage";
108        zip = fetchzip {
109          inherit hash;
110          url = "https://github.com/project-slippi/Ishiiruka-Playback/releases/download/v${version}/playback-${version}-Linux.zip";
111          stripRoot = false;
112        };
113        src = "${zip}/Slippi_Playback-x86_64.AppImage";
114      in
115        stdenvNoCC.mkDerivation {
116          inherit pname version;
117
118          src = appimageTools.wrapType2 {
119            inherit pname version src;
120            extraPkgs = pkgs: with pkgs; [curl zlib mpg123];
121
122            postInstall = ''
123              ls -la "$out"
124              wrapProgram $out/bin/${pname}-${version} \
125                --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}"
126            '';
127          };
128
129          installPhase = ''
130            runHook preInstall
131
132            mkdir -p "$out/bin"
133            cp -r "$src/bin" "$out"
134
135            runHook postInstall
136          '';
137        }) {};
138      slippi-launcher = pkgs.callPackage ({
139        stdenvNoCC,
140        appimageTools,
141        fetchurl,
142        copyDesktopItems,
143        version ? defaults.launcher.version,
144        hash ? defaults.launcher.hash,
145      }: let
146        pname = "slippi-launcher-appimage";
147
148        src = fetchurl {
149          inherit hash;
150          url = "https://github.com/project-slippi/slippi-launcher/releases/download/v${version}/Slippi-Launcher-${version}-x86_64.AppImage";
151        };
152
153        appImageContents = appimageTools.extractType2 {
154          inherit pname version src;
155        };
156      in
157        stdenvNoCC.mkDerivation {
158          inherit pname version;
159
160          src = appimageTools.wrapType2 {
161            inherit pname version src;
162            extraPkgs = pkgs: with pkgs; [curl zlib mpg123];
163
164            postInstall = ''
165              ls -la "$out"
166              wrapProgram $out/bin/${pname}-${version} \
167                --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}"
168            '';
169          };
170
171          # TODO: see if we can convince upstream to let us specify command line
172          # arguments to denote where the netplay and playback binaries are?
173          # this might eliminate the need for the home manager module
174          installPhase = ''
175            runHook preInstall
176
177            mkdir -p "$out/bin"
178            mkdir -p "$out/share/applications"
179            cp -r "$src/bin" "$out"
180            cp -r "${appImageContents}/$(readlink "${appImageContents}/slippi-launcher.png")" "$out/share/applications/"
181            sed '/Icon/d' "${appImageContents}/slippi-launcher.desktop" > "$out/share/applications/slippi-launcher.desktop"
182            sed '/Exec/d' "${appImageContents}/slippi-launcher.desktop" > "$out/share/applications/slippi-launcher.desktop"
183            echo "Icon=$out/share/applications/slippi-launcher.png" >> "$out/share/applications/slippi-launcher.desktop"
184            echo "Exec=$out/bin/${pname} %U" >> "$out/share/applications/slippi-launcher.desktop"
185
186            runHook postInstall
187          '';
188
189          nativeBuildInputs = [copyDesktopItems];
190        }) {};
191    });
192
193    checks = genPkgs (pkgs: {
194      inherit (outputs.packages.${pkgs.system}) slippi-launcher slippi-netplay slippi-playback;
195      git-hooks = git-hooks.lib.${pkgs.system}.run {
196        src = ./.;
197        hooks = {
198          alejandra.enable = true;
199        };
200      };
201      home-manager-module-test = pkgs.testers.runNixOSTest {
202        # a simple integration test to ensure that the home manager module works and boots a host
203        name = "home-manager-module-test";
204        nodes.machine = {
205          config,
206          pkgs,
207          ...
208        }: {
209          imports = [
210            home-manager.nixosModules.home-manager
211          ];
212          users.users.daniel = {
213            isNormalUser = true;
214            home = "/home/daniel";
215            createHome = true;
216            extraGroups = ["wheel" "users"];
217          };
218          home-manager.users.daniel = {
219            imports = with outputs.homeManagerModules; [
220              slippi-launcher
221            ];
222            slippi-launcher.enable = true;
223            home = {
224              username = "daniel";
225              homeDirectory = "/home/daniel";
226              stateVersion = "24.11";
227            };
228          };
229          system.stateVersion = "24.11";
230        };
231        testScript = {nodes, ...}: ''
232          machine.wait_for_unit("default.target")
233          print(machine.succeed("ls -laR /home/daniel/.config"))
234          print(machine.succeed("grep ${defaults.netplay.version} '/home/daniel/.config/Slippi Launcher/Settings'"))
235          print(machine.succeed("grep ${defaults.playback.version} '/home/daniel/.config/Slippi Launcher/Settings'"))
236        '';
237      };
238    });
239
240    nixosModules = {
241      default = {
242        imports = with outputs.nixosModules; [
243          gamecube-controller-adapter
244        ];
245      };
246
247      gamecube-controller-adapter = {
248        lib,
249        config,
250        ...
251      }: let
252        inherit (lib) mkEnableOption mkOption types mkIf;
253        cfg = config.gamecube-controller-adapter;
254      in {
255        # defaults here are true since we assume if you're importing the module, you
256        # want it on ;)
257        options.gamecube-controller-adapter = {
258          enable = mkEnableOption "Enable the optimal gamecube controller adapter experience." // {default = true;};
259
260          overclocking-kernel-module.enable = mkEnableOption "Turn on gamecube controller adapter overclocking kernel module." // {default = true;};
261
262          udev-rules.enable = mkEnableOption "Turn on udev rules for your gamecube controller adapter." // {default = true;};
263          udev-rules.rules = mkOption {
264            default = ''
265              ATTRS{idVendor}=="057e", ATTRS{idProduct}=="0337", MODE="666", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device" TAG+="uaccess"
266            '';
267            type = types.lines;
268            description = "To be appended to services.udev.extraRules if gcc.rules.enable is set.";
269          };
270        };
271
272        config = {
273          gamecube-controller-adapter.udev-rules.enable = mkIf cfg.enable true;
274          gamecube-controller-adapter.overclocking-kernel-module.enable = mkIf cfg.enable true;
275
276          services.udev.extraRules = mkIf cfg.udev-rules.enable cfg.udev-rules.rules;
277
278          boot.extraModulePackages = mkIf cfg.overclocking-kernel-module.enable [
279            # https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/linux/gcadapter-oc-kmod/default.nix
280            config.boot.kernelPackages.gcadapter-oc-kmod
281          ];
282          boot.kernelModules = mkIf cfg.overclocking-kernel-module.enable [
283            "gcadapter_oc"
284          ];
285        };
286      };
287    };
288
289    homeManagerModules = {
290      default = {
291        imports = with outputs.homeManagerModules; [
292          slippi-launcher
293        ];
294      };
295
296      slippi-launcher = {
297        lib,
298        pkgs,
299        config,
300        ...
301      }: let
302        inherit (lib) mkEnableOption mkOption types mkIf;
303        cfg = config.slippi-launcher;
304        flakePackages = outputs.packages.${pkgs.system};
305        netplay-package = version: hash:
306          flakePackages.slippi-netplay.overrideAttrs {
307            inherit version hash;
308          };
309        playback-package = version: hash:
310          flakePackages.slippi-playback.overrideAttrs {
311            inherit version hash;
312          };
313        launcher-package = version: hash:
314          flakePackages.slippi-launcher.overrideAttrs {
315            inherit version hash;
316          };
317      in {
318        # defaults here are true since we assume if you're importing the module, you
319        # want it on ;)
320        options.slippi-launcher = {
321          enable = mkEnableOption "Install Slippi Launcher" // {default = true;};
322
323          netplayVersion = mkOption {
324            default = defaults.netplay.version;
325            type = types.str;
326            description = "The version of Slippi Netplay to install.";
327          };
328          netplayHash = mkOption {
329            default = defaults.netplay.hash;
330            type = types.str;
331            description = "The hash of the Slippi Netplay AppImage to install.";
332          };
333
334          playbackVersion = mkOption {
335            default = defaults.playback.version;
336            type = types.str;
337            description = "The version of Slippi Playback to install.";
338          };
339          playbackHash = mkOption {
340            default = defaults.playback.hash;
341            type = types.str;
342            description = "The hash of the Slippi Playback AppImage to install.";
343          };
344
345          launcherVersion = mkOption {
346            default = defaults.launcher.version;
347            type = types.str;
348            description = "The version of Slippi Launcher to install.";
349          };
350          launcherHash = mkOption {
351            default = defaults.launcher.hash;
352            type = types.str;
353            description = "The hash of the Slippi Launcher AppImage to install.";
354          };
355
356          isoPath = mkOption {
357            default = "";
358            type = types.str;
359            description = "The path to an NTSC Melee ISO.";
360          };
361
362          launchMeleeOnPlay = mkEnableOption "Launch Melee in Dolphin when the Play button is pressed." // {default = true;};
363
364          enableJukebox = mkEnableOption "Enable in-game music via Slippi Jukebox. Incompatible with WASAPI." // {default = true;};
365
366          rootSlpPath = mkOption {
367            default = "${config.home.homeDirectory}/Slippi";
368            type = types.str;
369            description = "The folder where your SLP replays should be saved.";
370          };
371
372          useMonthlySubfolders = mkEnableOption "Save replays to monthly subfolders";
373
374          spectateSlpPath = mkOption {
375            default = "${cfg.rootSlpPath}/Spectate";
376            type = types.nullOr types.str;
377            description = "The folder where spectated games should be saved.";
378          };
379
380          extraSlpPaths = mkOption {
381            default = [];
382            type = types.listOf types.str;
383            description = "Choose any additional SLP directories that should show up in the replay browser.";
384          };
385        };
386        config = let
387          cfgNetplayPackage = netplay-package cfg.netplayVersion cfg.netplayHash;
388          cfgPlaybackPackage = playback-package cfg.playbackVersion cfg.playbackHash;
389          cfgLauncherPackage = launcher-package cfg.launcherVersion cfg.launcherHash;
390        in {
391          home.packages = [(mkIf cfg.enable cfgLauncherPackage)];
392          home.file.".config/Slippi Launcher/netplay/Slippi_Online-x86_64.AppImage" = {
393            enable = cfg.enable;
394            source = "${cfgNetplayPackage}/bin/Slippi_Online-x86_64.AppImage";
395            recursive = false;
396          };
397          home.file.".config/Slippi Launcher/netplay/Sys" = {
398            enable = cfg.enable;
399            source = "${pkgs.fetchzip {
400              url = "https://github.com/project-slippi/Ishiiruka/releases/download/v${cfg.netplayVersion}/FM-Slippi-${cfg.netplayVersion}-Linux.zip";
401              hash = cfg.netplayHash;
402              stripRoot = false;
403            }}/Sys";
404            recursive = false;
405          };
406          home.file.".config/Slippi Launcher/playback/Slippi_Playback-x86_64.AppImage" = {
407            enable = cfg.enable;
408            source = "${cfgPlaybackPackage}/bin/Slippi_Playback-x86_64.AppImage";
409            recursive = false;
410          };
411          home.file.".config/Slippi Launcher/playback/Sys" = {
412            enable = cfg.enable;
413            source = "${
414              pkgs.fetchzip {
415                url = "https://github.com/project-slippi/Ishiiruka-Playback/releases/download/v${cfg.playbackVersion}/playback-${cfg.playbackVersion}-Linux.zip";
416                hash = cfg.netplayHash;
417                stripRoot = false;
418              }
419            }/Sys";
420            recursive = false;
421          };
422          xdg.configFile."Slippi Launcher/Settings" = {
423            enable = cfg.enable;
424            source = let
425              jsonFormat = pkgs.formats.json {};
426            in
427              jsonFormat.generate "slippi-config" {
428                settings = {
429                  isoPath = cfg.isoPath;
430
431                  launchMeleeOnPlay = cfg.launchMeleeOnPlay;
432                  enableJukebox = cfg.enableJukebox;
433
434                  rootSlpPath = cfg.rootSlpPath;
435                  useMonthlySubfolders = cfg.useMonthlySubfolders;
436                  spectateSlpPath = cfg.spectateSlpPath;
437                  extraSlpPaths = cfg.extraSlpPaths;
438
439                  netplayDolphinPath = "${cfgNetplayPackage}/bin/";
440                  playbackDolphinPath = "${cfgPlaybackPackage}/bin/";
441
442                  autoUpdateLauncher = false;
443                };
444              };
445          };
446        };
447      };
448    };
449  };
450}