Skip to content

Commit 05ef888

Browse files
committed
Nix expr: make shellHook an output of default.nix, make shells directly within flake.nix
1 parent b9c2d44 commit 05ef888

File tree

3 files changed

+59
-32
lines changed

3 files changed

+59
-32
lines changed

default.nix

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ in {
150150
|| isVersionAtLeast "2.6" value.hawkSourceInfo.version))
151151
];
152152
latestVersionFrag = lib.head releaseFrags;
153-
combined = pp // asmsFromReleaseArtifacts // releasesEmuHawkInstallables // {
154-
inherit depsForHistoricalRelease populateHawkSourceInfo releaseTagSourceInfos;
155-
inherit (emuhawk-local.assemblies) libretroCores;
153+
combined = let
154+
launchScriptsForLocalBuild = launchScriptsFor emuhawk-local.assemblies true;
155+
in (pp // asmsFromReleaseArtifacts // releasesEmuHawkInstallables // {
156+
inherit depsForHistoricalRelease populateHawkSourceInfo releaseTagSourceInfos launchScriptsForLocalBuild;
157+
inherit (emuhawk-local.assemblies) libretroCores;
156158
bizhawkAssemblies = pp.buildAssembliesFor (fillTargetOSDifferences hawkSourceInfoDevBuild);
157159
"bizhawkAssemblies-${latestVersionFrag}" = pp.buildAssembliesFor
158160
(fillTargetOSDifferences releaseTagSourceInfos."info-${latestVersionFrag}");
@@ -172,8 +174,27 @@ in {
172174
IDEs = {
173175
kate = [ kate omnisharp-roslyn ];
174176
};
175-
launchScriptsForLocalBuild = launchScriptsFor emuhawk-local.assemblies true;
176-
};
177+
shellHook = drv: ''
178+
export BIZHAWKBUILD_HOME='${builtins.toString ./.}'
179+
export BIZHAWK_HOME="$BIZHAWKBUILD_HOME/output/"
180+
ldLibPath='${lib.makeLibraryPath drv.buildInputs}' # for running tests
181+
if [ -z "$LD_LIBRARY_PATH" ]; then
182+
export LD_LIBRARY_PATH="$ldLibPath"
183+
else
184+
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$ldLibPath"
185+
fi
186+
alias discohawk-monort-local='${launchScriptsForLocalBuild.discohawk}'
187+
alias emuhawk-monort-local='${launchScriptsForLocalBuild.emuhawk}'
188+
case "$-" in *i*)
189+
pfx="$(realpath --relative-to="$PWD" "$BIZHAWKBUILD_HOME")/"
190+
if [ "$pfx" = "./" ]; then pfx=""; fi
191+
printf "%s\n%s\n" \
192+
"Run ''${pfx}Dist/Build{Debug,Release}.sh to build the solution. You may need to clean up with ''${pfx}Dist/CleanupBuildOutputDirs.sh." \
193+
"Once built, running {discohawk,emuhawk}-monort-local will pull from ''${pfx}output/* and use Mono from Nixpkgs."
194+
;;
195+
esac
196+
'';
197+
});
177198
in combined // lib.listToAttrs (lib.concatLists (builtins.map
178199
(f: [
179200
{ name = f "latest-bin"; value = combined.${f "${latestVersionFrag}-bin"}; }

flake.nix

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,38 @@
3636
) nixpkgsFor;
3737
devShells = mapAttrs (
3838
system: pkgs:
39-
# ./shell.nix outputs some non-derivation attributes and some extraneous derivations, so we have to filter those out
40-
(lib.filterAttrs (
41-
name: val: lib.isDerivation val && name != "stdenv" && name != "out" && name != "inputDerivation"
42-
) (import ./shell.nix { inherit system pkgs; }))
43-
// {
44-
default = self.devShells.${system}.emuhawk-latest;
45-
}
39+
let
40+
avail = import ./default.nix { inherit system pkgs; };
41+
mkShellCustom =
42+
drv:
43+
pkgs.mkShell {
44+
packages = with pkgs; [
45+
git
46+
powershell
47+
];
48+
inputsFrom = [ drv ];
49+
shellHook = avail.shellHook drv;
50+
};
51+
shells = lib.pipe avail [
52+
(lib.mapAttrs (
53+
name: drv: if lib.hasPrefix "bizhawkAssemblies-" name then drv else drv.assemblies or null
54+
))
55+
(lib.filterAttrs (_: drv: drv != null))
56+
(lib.mapAttrs (
57+
_: asms:
58+
lib.traceIf (lib.hasSuffix "-bin" asms.name)
59+
"the attr specified packages BizHawk from release artifacts; some builddeps may be missing from this shell"
60+
mkShellCustom
61+
asms
62+
))
63+
];
64+
in
65+
(
66+
shells
67+
// {
68+
default = self.devShells.${system}.emuhawk-latest;
69+
}
70+
)
4671
) nixpkgsFor;
4772
};
4873
}

shell.nix

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,7 @@
2525
++ lib.optionals useVSCode [] #TODO https://devblogs.microsoft.com/dotnet/csharp-dev-kit-now-generally-available/ https://learn.microsoft.com/en-us/training/modules/implement-visual-studio-code-debugging-tools/
2626
;
2727
inputsFrom = [ drv ];
28-
shellHook = ''
29-
export BIZHAWKBUILD_HOME='${builtins.toString ./.}'
30-
export BIZHAWK_HOME="$BIZHAWKBUILD_HOME/output/"
31-
ldLibPath='${lib.makeLibraryPath drv.buildInputs}' # for running tests
32-
if [ -z "$LD_LIBRARY_PATH" ]; then
33-
export LD_LIBRARY_PATH="$ldLibPath"
34-
else
35-
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$ldLibPath"
36-
fi
37-
alias discohawk-monort-local='${avail.launchScriptsForLocalBuild.discohawk}'
38-
alias emuhawk-monort-local='${avail.launchScriptsForLocalBuild.emuhawk}'
39-
case "$-" in *i*)
40-
pfx="$(realpath --relative-to="$PWD" "$BIZHAWKBUILD_HOME")/"
41-
if [ "$pfx" = "./" ]; then pfx=""; fi
42-
printf "%s\n%s\n" \
43-
"Run ''${pfx}Dist/Build{Debug,Release}.sh to build the solution. You may need to clean up with ''${pfx}Dist/CleanupBuildOutputDirs.sh." \
44-
"Once built, running {discohawk,emuhawk}-monort-local will pull from ''${pfx}output/* and use Mono from Nixpkgs."
45-
;;
46-
esac
47-
'';
28+
shellHook = avail.shellHook drv;
4829
};
4930
shells = lib.pipe avail [
5031
(lib.mapAttrs (name: drv: if lib.hasPrefix "bizhawkAssemblies-" name then drv else drv.assemblies or null))

0 commit comments

Comments
 (0)