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