about summary refs log tree commit diff
path: root/pkgs/games/dwarf-fortress/default.nix
blob: ee02364a40a4a05b220e9212a1a6666fe1ddddec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
{ stdenv, stdenvNoCC, gccStdenv, lib, recurseIntoAttrs, libsForQt5, newScope, texliveBasic, perlPackages, jdk8, jre8 }:

# To whomever it may concern:
#
# This directory menaces with spikes of Nix code. It is terrifying.
#
# If this is your first time here, you should probably install the dwarf-fortress-full package,
# for instance with:
#
# environment.systemPackages = [ pkgs.dwarf-fortress-packages.dwarf-fortress-full ];
#
# You can adjust its settings by using override, or compile your own package by
# using the other packages here.
#
# For example, you can enable the FPS indicator, disable the intro, pick a
# theme other than phoebus (the default for dwarf-fortress-full), _and_ use
# an older version with something like:
#
# environment.systemPackages = [
#   (pkgs.dwarf-fortress-packages.dwarf-fortress-full.override {
#      dfVersion = "0.44.11";
#      theme = "cla";
#      enableIntro = false;
#      enableFPS = true;
#   })
# ]
#
# Take a look at lazy-pack.nix to see all the other options.
#
# You will find the configuration files in ~/.local/share/df_linux/data/init. If
# you un-symlink them and edit, then the scripts will avoid overwriting your
# changes on later launches, but consider extending the wrapper with your
# desired options instead.

let
  inherit (lib)
    attrNames
    getAttr
    importJSON
    listToAttrs
    optionalAttrs
    recurseIntoAttrs
    replaceStrings
    versionAtLeast
    ;

  callPackage = newScope self;

  # The latest Dwarf Fortress version. Maintainers: when a new version comes
  # out, ensure that (unfuck|dfhack|twbt) are all up to date before changing
  # this. Note that unfuck and twbt are not required for 50.
  latestVersion = "50.12";

  # Converts a version to a package name.
  versionToName = version: "dwarf-fortress_${replaceStrings ["."] ["_"] version}";

  # A map of names to each Dwarf Fortress package we know about.
  df-games = listToAttrs (map
    (dfVersion: {
      name = versionToName dfVersion;
      value =
        let
          isAtLeast50 = versionAtLeast dfVersion "50.0";

          dwarf-fortress-unfuck = optionalAttrs (!isAtLeast50) (callPackage ./unfuck.nix { inherit dfVersion; });

          dwarf-fortress = callPackage ./game.nix {
            inherit dfVersion;
            inherit dwarf-fortress-unfuck;
          };

          twbt = optionalAttrs (!isAtLeast50) (callPackage ./twbt { inherit dfVersion; });

          dfhack = callPackage ./dfhack {
            inherit (perlPackages) XMLLibXML XMLLibXSLT;
            inherit dfVersion;
            stdenv = gccStdenv;
          };

          dwarf-therapist = libsForQt5.callPackage ./dwarf-therapist/wrapper.nix {
            inherit dwarf-fortress;
            dwarf-therapist = (libsForQt5.callPackage ./dwarf-therapist {
              texlive = texliveBasic.withPackages (ps: with ps; [ float caption wrapfig adjmulticol sidecap preprint enumitem ]);
            }).override (optionalAttrs (!isAtLeast50) {
              # 41.2.5 is the last version to support Dwarf Fortress 0.47.
              version = "41.2.5";
              hash = "sha256-xfYBtnO1n6OcliVt07GsQ9alDJIfWdVhtuyWwuvXSZs=";
            });
          };
        in
        callPackage ./wrapper {
          inherit (self) themes;
          inherit dwarf-fortress twbt dfhack dwarf-therapist;

          jdk = jdk8; # TODO: remove override https://github.com/NixOS/nixpkgs/pull/89731
        };
    })
    (attrNames self.df-hashes));

  self = rec {
    df-hashes = importJSON ./game.json;

    # Aliases for the latest Dwarf Fortress and the selected Therapist install
    dwarf-fortress = getAttr (versionToName latestVersion) df-games;
    dwarf-therapist = dwarf-fortress.dwarf-therapist;
    dwarf-fortress-original = dwarf-fortress.dwarf-fortress;

    dwarf-fortress-full = callPackage ./lazy-pack.nix {
      inherit df-games versionToName latestVersion;
    };

    soundSense = callPackage ./soundsense.nix { };

    legends-browser = callPackage ./legends-browser {
      jre = jre8; # TODO: remove override https://github.com/NixOS/nixpkgs/pull/89731
    };

    themes = recurseIntoAttrs (callPackage ./themes {
      stdenv = stdenvNoCC;
    });

    # Theme aliases
    phoebus-theme = themes.phoebus;
    cla-theme = themes.cla;
  };

in
self // df-games