cataclysmDDA: add utility function attachPkgs

This commit is contained in:
Mitsuhiro Nakamura 2020-11-12 10:48:19 +09:00
parent 19deef39c7
commit 0c02a5599c
4 changed files with 36 additions and 16 deletions

View File

@ -33,7 +33,8 @@ let
buildMod buildMod
buildSoundPack buildSoundPack
buildTileSet buildTileSet
wrapCDDA; wrapCDDA
attachPkgs;
inherit pkgs; inherit pkgs;
}; };

View File

@ -1,4 +1,4 @@
{ lib, callPackage, CoreFoundation, fetchFromGitHub, pkgs, wrapCDDA { lib, callPackage, CoreFoundation, fetchFromGitHub, pkgs, wrapCDDA, attachPkgs
, tiles ? true, Cocoa , tiles ? true, Cocoa
, debug ? false , debug ? false
, useXdgDir ? false , useXdgDir ? false
@ -26,11 +26,6 @@ let
"VERSION=git-${version}-${lib.substring 0 8 src.rev}" "VERSION=git-${version}-${lib.substring 0 8 src.rev}"
]; ];
passthru = common.passthru // {
pkgs = pkgs.override { build = self; };
withMods = wrapCDDA self;
};
meta = common.meta // { meta = common.meta // {
maintainers = with lib.maintainers; maintainers = with lib.maintainers;
common.meta.maintainers ++ [ rardiol ]; common.meta.maintainers ++ [ rardiol ];
@ -38,4 +33,4 @@ let
}); });
in in
self attachPkgs pkgs self

View File

@ -1,6 +1,6 @@
{ callPackage }: { callPackage }:
{ rec {
buildMod = callPackage ./builder.nix { buildMod = callPackage ./builder.nix {
type = "mod"; type = "mod";
}; };
@ -14,4 +14,33 @@
}; };
wrapCDDA = callPackage ./wrapper.nix {}; wrapCDDA = callPackage ./wrapper.nix {};
# Required to fix `pkgs` and `withMods` attrs after applying `overrideAttrs`.
#
# Example:
# let
# myBuild = cataclysmDDA.jenkins.latest.tiles.overrideAttrs (_: {
# x = "hello";
# });
#
# # This refers to the derivation before overriding! So, `badExample.x` is not accessible.
# badExample = myBuild.withMods (_: []);
#
# # `myBuild` is correctly referred by `withMods` and `goodExample.x` is accessible.
# goodExample = let
# inherit (cataclysmDDA) attachPkgs pkgs;
# in
# (attachPkgs pkgs myBuild).withMods (_: []);
# in
# goodExample.x # returns "hello"
attachPkgs = pkgs: super:
let
self = super.overrideAttrs (old: {
passthru = old.passthru // {
pkgs = pkgs.override { build = self; };
withMods = wrapCDDA self;
};
});
in
self;
} }

View File

@ -1,4 +1,4 @@
{ lib, callPackage, CoreFoundation, fetchFromGitHub, pkgs, wrapCDDA { lib, callPackage, CoreFoundation, fetchFromGitHub, pkgs, wrapCDDA, attachPkgs
, tiles ? true, Cocoa , tiles ? true, Cocoa
, debug ? false , debug ? false
, useXdgDir ? false , useXdgDir ? false
@ -19,11 +19,6 @@ let
sha256 = "15l6w6lxays7qmsv0ci2ry53asb9an9dh7l7fc13256k085qcg68"; sha256 = "15l6w6lxays7qmsv0ci2ry53asb9an9dh7l7fc13256k085qcg68";
}; };
passthru = common.passthru // {
pkgs = pkgs.override { build = self; };
withMods = wrapCDDA self;
};
meta = common.meta // { meta = common.meta // {
maintainers = with lib.maintainers; maintainers = with lib.maintainers;
common.meta.maintainers ++ [ skeidel ]; common.meta.maintainers ++ [ skeidel ];
@ -31,4 +26,4 @@ let
}); });
in in
self attachPkgs pkgs self