Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dwarf-fortress: Refactor, round 2: let the user pick which version of the lazy pack to install #43470

Merged
merged 8 commits into from Sep 9, 2018

Conversation

numinit
Copy link
Contributor

@numinit numinit commented Jul 13, 2018

Motivation for this change

Dwarf Fortress unfuck, dfhack, and TWBT are tied to specific Dwarf Fortress versions, which makes the package harder to maintain and useless for people who want to run an older (or newer) version of the lazy pack. Let the user decide the Dwarf Fortress version, and we'll choose the versions of unfuck, dfhack, and TWBT for them based on the latest available for those versions.

Also, improve the launch behavior of Dwarf Therapist by creating a symlink to memory_layouts in the user's home directory, similar to how Dwarf Fortress already behaves.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

@numinit numinit changed the title dwarf-fortress: [WIP] refactor, round 2: support multiple unfuck/dfhack/TWBT versions dwarf-fortress: [WIP] refactor, round 2: dwarf-therapist 40.1.1; dwarf-fortress 0.44.12; support multiple unfuck/dfhack/TWBT versions Jul 13, 2018
cd "$install_dir/share/dwarftherapist"
update_path memory_layouts

QT_QPA_PLATFORM_PLUGIN_PATH="@qt_plugin_path@" \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better way to fix this? Seems to be the same as #37864.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it’s pretty much unavoidable. You could use wrapProgram though (it will generate a file that looks pretty close to this anyway).

--subst-var-by stdenv_shell ${stdenv.shell} \
--subst-var-by install $out \
--subst-var-by therapist ${dwarf-therapist} \
--subst-var-by qt_plugin_path "${pkgs.qt5.qtbase}/lib/qt-5.11/plugins/platforms"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be hardcoding the version, need to fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@numinit
Copy link
Contributor Author

numinit commented Jul 13, 2018

dfhack is currently broken with this, I don't think we're updating the MD5 correctly anymore. God this package is complicated...

@Anton-Latukha
Copy link
Contributor

I wanted to say thanks.

I love Dwarf Fortress. But could not solve the puzzle fully, what all packages do, and how to make tilesets/LNP work.

Please, can you add comprehensive descriptions to packages? So people can understand what are those and how it works together.

@numinit
Copy link
Contributor Author

numinit commented Jul 13, 2018

Yeah, it could use some examples. The docs are a little (accidentally) misleading in some places.

Here's basically how to install the lazy pack with FPS enabled and a theme, assuming your reference to the unstable nixpkgs tree is called unstable:

      (unstable.dwarf-fortress-packages.dwarf-fortress-full.override {
        theme = "cla";
        enableFPS = true;
      })


dwarf-fortress-full = callPackage ./lazy-pack.nix { };

dfhack = callPackage ./dfhack {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little concerned about having too many versions of each package here. Does dfhack not support older versions of dwarf fortress?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. If you check their release page, they dropped 0.44.11 support in the 0.44.12-alpha1 release. The base game sometimes changes too much for them to retain backwards compatibility.

Copy link
Contributor Author

@numinit numinit Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, looking at their release history, they always break backwards compatibility when Dwarf Fortress changes. Oi...

pkgs/games/dwarf-fortress/default.nix Outdated Show resolved Hide resolved
value =
let
# I can't believe this syntax works. Spikes of Nix code indeed...
dwarf-fortress = callPackage ./game.nix {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to put these in the callPackage wrapper.nix {...}. It should only be needed there. I think the same thing can be done for dfhack as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've inlined those JSON files.

Maybe my knowledge of Nix is incomplete, but I think we might be stuck with the let ... in syntax here, because of the dependencies between packages?

@@ -59,7 +75,6 @@ let

legends-browser = callPackage ./legends-browser {};

twbt = callPackage ./twbt {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping this would be version independent. Is that not how it works currently?

Copy link
Contributor Author

@numinit numinit Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Check out mifki/df-twbt:patches.hpp; there is a large if/elif defined(DF_$VERSION) chain. That version code is originally set in mifki's Makefile.

pkgs/games/dwarf-fortress/dfhack/dfhack.json Outdated Show resolved Hide resolved
cd "$install_dir/share/dwarftherapist"
update_path memory_layouts

QT_QPA_PLATFORM_PLUGIN_PATH="@qt_plugin_path@" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it’s pretty much unavoidable. You could use wrapProgram though (it will generate a file that looks pretty close to this anyway).

# therefore uses many relative paths.
wrapProgram $out/bin/dwarftherapist \
--run "cd $out/share/dwarftherapist"
buildCommand = ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong. buildCommand will override symlinkJoin behavior. Is there a reason to use this instead of postBuild?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running in nix-shell, it seemed like the "unsymlink" code was trying to to stomp over a different package's init directory, and it complained about not being able able to delete init.txt due to permissions.

Copy link
Contributor Author

@numinit numinit Jul 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically, here's the log when we use postBuild rebased against latest master. The symlink alias (dwarftherapist/DwarfTherapist) now fails.

I should also note that I'm trying to use it in a container.

building '/nix/store/5r6wa7f8hlymgbf2ms90c9ljmsxy5dph-dwarf-therapist-40.1.1.drv'...
chmod: changing permissions of '/nix/store/q8pqivs0xh34vgil8hmh2xkzpwk18k0c-dwarf-therapist-40.1.1/bin/dwarftherapist': Operation not permitted
builder for '/nix/store/5r6wa7f8hlymgbf2ms90c9ljmsxy5dph-dwarf-therapist-40.1.1.drv' failed with exit code 1
cannot build derivation '/nix/store/w1ld9xwxchf7zwydi9zd1wzf7b88pv7k-dwarf-fortress-full.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/id7vygj7inr00zlwzzvynbj8z182nsa2-system-path.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/5g52k9mq297c8allssnknxhmrzn4ma8f-nixos-system-df-18.03.132750.91b286c8935.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/bj4kbigg0x3cfy7kxy59axkn6ssgl3v4-etc-df.conf.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/r315hpn7122l851h15715vlvhak5lf4p-unit-container-df.service.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/pqkkn9h8qbaawqbla0yg5wadx0r67rpp-etc.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/v88s4vvcggplz3d6ik50v3z5qhbm3xsx-nixos-system-battlespire-18.03.132750.91b286c8935.drv': 1 dependencies couldn't be built
error: build of '/nix/store/v88s4vvcggplz3d6ik50v3z5qhbm3xsx-nixos-system-battlespire-18.03.132750.91b286c8935.drv' failed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to use stdenv.mkDerivation. Is there a reason why symlinkJoin was necessary for the wrapper? It seems to work fine using stdenv.mkDerivation and preferLocalBuild like the DF wrapper.

};
in

stdenv.mkDerivation rec {
name = "dwarf-fortress-${dwarf-fortress.dfVersion}";

compatible = lib.all (x: assert (x.dfVersion == dwarf-fortress.dfVersion); true) pkgs;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there may still be a use for this. Need to hear from other maintainers first on need for it though.

@numinit
Copy link
Contributor Author

numinit commented Jul 13, 2018

Still a few more changes necessary, good feedback so far.

Apart from the code review comments, here's some other stuff I need to do:

  • fix dfhack md5
  • don't hardcode qt version
  • let users override dfVersion to pick one other than the default
  • update to dfhack 0.44.12-r1
  • update to TWBT 6.53
  • figure out why TWBT won't work in xf86-video-dummy build TWBT from source
  • make Therapist install support the MD5 of each DF version
  • fix Git: bug in dfhack
  • update to Therapist 40.1.2

Code review comments:

  • inline JSON files
  • /default.nix: move let statements into callPackage wrapper.nix
  • look into /dwarf-therapist/wrapper.nix buildCommand, probably should be postBuild just changed it to a normal derivation

@numinit
Copy link
Contributor Author

numinit commented Jul 15, 2018

It looks like dfhack isn't working correctly because the wrapper's postBuild is never running. Any reason for this?

@numinit
Copy link
Contributor Author

numinit commented Jul 15, 2018

Missed that error this whole time... the MD5 fixup wasn't running in the correct environment.

@numinit numinit changed the title dwarf-fortress: [WIP] refactor, round 2: dwarf-therapist 40.1.1; dwarf-fortress 0.44.12; support multiple unfuck/dfhack/TWBT versions dwarf-fortress: [WIP] Refactor, round 2: let the user pick which version of the lazy pack to install Jul 15, 2018
@numinit numinit changed the title dwarf-fortress: [WIP] Refactor, round 2: let the user pick which version of the lazy pack to install dwarf-fortress: Refactor, round 2: let the user pick which version of the lazy pack to install Jul 15, 2018
@numinit
Copy link
Contributor Author

numinit commented Jul 15, 2018

Removing the [WIP] tag; most of the important changes are there now. This fixes the fact that you could potentially end up with an incompatible Dwarf Fortress/dfhack/Dwarf Therapist/unfuck combination before.

@matthewbauer matthewbauer merged commit e4db8a9 into NixOS:master Sep 9, 2018
@@ -1,4 +1,4 @@
{lib, fetchFromGitHub}:
{lib, fetchFromGitHub, ...}:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the ...

Copy link
Contributor Author

@numinit numinit Oct 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, was there previously. Can remove it.

Edit: NVM, I added it. Will still remove it. :-)

dfVersion = "0.44.12";
version = "${dfVersion}-r1";
dfhack-releases = {
"0.43.05" = {
Copy link
Member

@Mic92 Mic92 Oct 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on what criteria are releases included here?

Copy link
Member

@Mic92 Mic92 Oct 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to have less versions listed here, because it makes the build matrix one has to test rather big.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthewbauer added them in #43085. I agree, some of these versions are rather old.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants