fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
3.7 KiB128 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6  cfg = config.programs.sm64ex;
7
8  # This is required for tests, we cannot overwrite the dummy package.
9  package = if cfg.region == null && cfg.baserom == null
10  && cfg.extraCompileFlags == null then
11    cfg.package
12
13  else
14    cfg.package.override (attrs:
15      { } // optionalAttrs (cfg.region != null) { region = cfg.region; }
16      // optionalAttrs (cfg.baserom != null) { baseRom = cfg.baserom; }
17      // optionalAttrs (cfg.extraCompileFlags != null) {
18        compileFlags = cfg.extraCompileFlags;
19      });
20
21  mkConfig = key: value:
22    let
23      generatedValue = if isBool value then
24        (if value then "true" else "false")
25      else if isList value then
26        concatStringsSep " " value
27      else
28        toString value;
29    in "${key} ${generatedValue}";
30
31in {
32  meta.maintainers = [ maintainers.ivar ];
33
34  options.programs.sm64ex = {
35    enable = mkEnableOption "sm64ex";
36
37    package = mkOption {
38      type = types.package;
39      default = pkgs.sm64ex;
40      description = "The sm64ex package to use.";
41    };
42
43    region = mkOption {
44      type = types.nullOr (types.enum [ "us" "eu" "jp" ]);
45      default = null;
46      defaultText =
47        literalExpression "us"; # This is set both in nixpkgs and upstream
48      description = ''
49        Your baserom's region. Note that only "us", "eu", and "jp" are supported.
50      '';
51      example = literalExpression "jp";
52    };
53
54    baserom = mkOption {
55      type = types.nullOr types.path;
56      default = null;
57      description =
58        "The path to the Super Mario 64 baserom to extract assets from.";
59      example = literalExpression "/home/foo/baserom.us.z64";
60    };
61
62    extraCompileFlags = mkOption {
63      type = with types; nullOr (listOf str);
64      default = null;
65      description = ''
66        Extra flags to pass to the compiler. See
67        <https://github.com/sm64pc/sm64ex/wiki/Build-options>
68        for more information.
69      '';
70      example = literalExpression ''
71        [
72          "BETTERCAMERA=1"
73          "NODRAWINGDISTANCE=1"
74        ];
75      '';
76    };
77
78    settings = mkOption {
79      type = with types;
80        nullOr (attrsOf (either str (either int (either bool (listOf str)))));
81      default = null;
82      description =
83        "Settings for sm64ex's {file}`$XDG_DATA_HOME/sm64pc/sm64config.txt` file.";
84      example = literalExpression ''
85        {
86          fullscreen = false;
87          window_x = 0;
88          window_y = 0;
89          window_w = 1920;
90          window_h = 1080;
91          vsync = 1;
92          texture_filtering = 1;
93          master_volume = 127;
94          music_volume = 127;
95          sfx_volume = 127;
96          env_volume = 127;
97          key_a = [ "0026" "1000" "1103" ];
98          key_b = [ "0033" "1002" "1101" ];
99          key_start = [ "0039" "1006" "ffff" ];
100          key_l = [ "0034" "1007" "1104" ];
101          key_r = [ "0036" "100a" "1105" ];
102          key_z = [ "0025" "1009" "1102" ];
103          key_cup = [ "100b" "ffff" "ffff" ];
104          key_cdown = [ "100c" "ffff" "ffff" ];
105          key_cleft = [ "100d" "ffff" "ffff" ];
106          key_cright = [ "100e" "ffff" "ffff" ];
107          key_stickup = [ "0011" "ffff" "ffff" ];
108          key_stickdown = [ "001f" "ffff" "ffff" ];
109          key_stickleft = [ "001e" "ffff" "ffff" ];
110          key_stickright = [ "0020" "ffff" "ffff" ];
111          stick_deadzone = 16;
112          rumble_strength = 10;
113          skip_intro = 1;
114        };
115      '';
116    };
117  };
118
119  config = let
120    configFile = optionals (cfg.settings != null)
121      (concatStringsSep "\n" ((mapAttrsToList mkConfig cfg.settings)));
122  in mkIf cfg.enable {
123    home.packages = [ package ];
124
125    xdg.dataFile."sm64pc/sm64config.txt" =
126      mkIf (cfg.settings != null) { text = configFile; };
127  };
128}