-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathflake.nix
More file actions
215 lines (185 loc) · 7.1 KB
/
flake.nix
File metadata and controls
215 lines (185 loc) · 7.1 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
{
description = "The Puzzle Pits - 1995 DOS puzzle game ported to modern systems";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
# Game data package - downloads original assets
gameDataPackage = pkgs.stdenv.mkDerivation {
pname = "puzzle-pits-data";
version = "1.0";
src = pkgs.fetchzip {
url = "https://archive.org/download/puzzle-pits/pits95.zip";
sha256 = "sha256-CIWSZReZ//qrP5ek1I5/g/aADr3LiZwU7C40aG4bELY=";
stripRoot = false;
};
installPhase = ''
mkdir -p $out/share/puzzle-pits
cp -r PITS95/* $out/share/puzzle-pits/
# Create lowercase versions for Linux compatibility
mkdir -p $out/share/puzzle-pits/lowercase
for file in PITS95/*.DAT PITS95/*.FNT; do
if [ -f "$file" ]; then
basename_lower=$(basename "$file" | tr '[:upper:]' '[:lower:]')
cp "$file" "$out/share/puzzle-pits/lowercase/$basename_lower"
fi
done
# Create lowercase levels directory
if [ -d "PITS95/LEVELS" ]; then
mkdir -p $out/share/puzzle-pits/lowercase/levels
for level in PITS95/LEVELS/*.PIT; do
if [ -f "$level" ]; then
basename_lower=$(basename "$level" | tr '[:upper:]' '[:lower:]')
cp "$level" "$out/share/puzzle-pits/lowercase/levels/$basename_lower"
fi
done
fi
'';
};
# Common build function
buildPuzzlePits = { withSDL ? false }: pkgs.stdenv.mkDerivation {
pname = "puzzle-pits${if withSDL then "-sdl" else ""}";
version = "1.0";
src = ./.;
nativeBuildInputs = [ pkgs.zig ] ++
(if withSDL then [ pkgs.pkg-config ] else []);
buildInputs = (if withSDL then [ pkgs.SDL2 ] else []);
buildPhase = ''
export HOME=$TMPDIR
# Build using unified Zig build system
${if withSDL then "zig build" else "zig build -Dsdl=false"}
'';
installPhase = ''
mkdir -p $out/bin
# Copy executables
cp zig-out/bin/* $out/bin/
# Copy game data
mkdir -p $out/share/puzzle-pits
cp -r ${gameDataPackage}/share/puzzle-pits/* $out/share/puzzle-pits/
# Create wrapper scripts that set up game data
for exe in $out/bin/puzzle-pits*; do
if [ -f "$exe" ]; then
mv "$exe" "$exe.real"
cat > "$exe" << EOF
#!/bin/bash
cd "\$(dirname "\$0")/../share/puzzle-pits"
exec "\$(dirname "\$0")/\$(basename "$exe").real" "\$@"
EOF
chmod +x "$exe"
fi
done
'';
meta = with pkgs.lib; {
description = "The Puzzle Pits - Classic 1995 DOS puzzle game";
homepage = "https://github.com/your-repo/the-puzzle-pits";
license = licenses.unfree; # Original game license
platforms = platforms.unix;
maintainers = [ ];
};
};
in {
# Main packages
packages = {
default = self.packages.${system}.puzzle-pits-sdl;
puzzle-pits-sdl = buildPuzzlePits { withSDL = true; };
puzzle-pits = buildPuzzlePits { withSDL = false; };
puzzle-pits-data = gameDataPackage;
};
# Development environments
devShells = {
default = self.devShells.${system}.sdl;
# Full development environment with SDL2
sdl = pkgs.mkShell {
buildInputs = with pkgs; [
zig
SDL2
pkg-config
gcc
curl
unzip
];
shellHook = ''
echo "🎮 The Puzzle Pits Development Environment (SDL2)"
echo ""
echo "Quick start:"
echo " make setup # Download game data and build"
echo " make run # Run the game"
echo ""
echo "Build commands:"
echo " make sdl # Build with SDL2 (full game)"
echo " make nosdl # Build without SDL2 (stub mode)"
echo " make test # Run tests"
echo " make clean # Clean artifacts"
echo ""
echo "All commands use the unified Zig build system."
echo ""
# Auto-download game data if not present
if [ ! -d "PITS95" ] && [ ! -f "tiles1.dat" ]; then
echo "⬇️ Auto-downloading game data..."
make download-data
echo ""
fi
'';
};
# Minimal development environment without SDL2
minimal = pkgs.mkShell {
buildInputs = with pkgs; [
zig
gcc
curl
unzip
];
shellHook = ''
echo "🔧 The Puzzle Pits Development Environment (Minimal)"
echo ""
echo "Quick start:"
echo " make nosdl # Build without SDL2"
echo " make test # Run tests"
echo ""
echo "Note: SDL2 not available in this shell."
echo "Use 'nix develop' for full SDL2 support."
echo ""
# Auto-download game data if not present
if [ ! -d "PITS95" ] && [ ! -f "tiles1.dat" ]; then
echo "⬇️ Auto-downloading game data..."
make download-data
echo ""
fi
'';
};
};
# Development apps
apps = {
default = self.apps.${system}.puzzle-pits;
puzzle-pits = {
type = "app";
program = "${self.packages.${system}.puzzle-pits-sdl}/bin/puzzle-pits";
};
demo = {
type = "app";
program = "${self.packages.${system}.puzzle-pits-sdl}/bin/puzzle-pits-demo";
};
};
# Hydra/CI jobs
checks = {
puzzle-pits-sdl = self.packages.${system}.puzzle-pits-sdl;
puzzle-pits = self.packages.${system}.puzzle-pits;
# Test build without SDL2
test-build-nosdl = pkgs.runCommand "test-build-nosdl" {
buildInputs = [ pkgs.zig ];
} ''
cp -r ${./.} source
cd source
chmod -R u+w .
export HOME=$TMPDIR
zig build -Dsdl=false
touch $out
'';
};
}
);
}