a mega cool windows xp app
1{
2 description = "Shortwave Radio Tuner - Win32 App for Windows XP";
3
4 inputs = {
5 nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
6 flake-parts.url = "github:hercules-ci/flake-parts";
7 systems.url = "github:nix-systems/default";
8 };
9
10 outputs =
11 inputs@{ flake-parts, systems, ... }:
12 flake-parts.lib.mkFlake { inherit inputs; } {
13 imports = [ ];
14 systems = import systems;
15 perSystem =
16 { self', pkgs, ... }:
17 {
18 packages = {
19 shortwave = pkgs.stdenv.mkDerivation {
20 name = "shortwave";
21 version = "1.0.0";
22 src = ./.;
23
24 nativeBuildInputs = with pkgs; [
25 cmake
26 pkgsCross.mingw32.buildPackages.gcc
27 ];
28
29 buildInputs = with pkgs.pkgsCross.mingw32; [
30 windows.mingw_w64
31 ];
32
33 configurePhase = ''
34 export CC=${pkgs.pkgsCross.mingw32.buildPackages.gcc}/bin/i686-w64-mingw32-gcc
35 export CXX=${pkgs.pkgsCross.mingw32.buildPackages.gcc}/bin/i686-w64-mingw32-g++
36 export CMAKE_SYSTEM_NAME=Windows
37 export CMAKE_C_COMPILER=$CC
38 export CMAKE_CXX_COMPILER=$CXX
39 '';
40
41 buildPhase = ''
42 export LDFLAGS="-static -static-libgcc -static-libstdc++"
43
44 # Check if BASS files exist in libs directory
45 if [ -f "libs/bass.h" ] && [ -f "libs/bass.lib" ]; then
46 echo "BASS files found in libs/ - building with audio integration"
47 else
48 echo "BASS files not found in libs/ - building without audio integration"
49 # Disable BASS in the source
50 sed -i 's|#include "libs/bass.h"|// #include "libs/bass.h"|' main.cpp
51 sed -i 's|libs/bass.lib||' CMakeLists.txt
52 fi
53
54 cmake -DCMAKE_BUILD_TYPE=Release \
55 -DCMAKE_SYSTEM_NAME=Windows \
56 -DCMAKE_C_COMPILER=$CC \
57 -DCMAKE_CXX_COMPILER=$CXX \
58 -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS" .
59 make VERBOSE=1
60 '';
61
62 installPhase = ''
63 mkdir -p $out/bin
64 cp Shortwave.exe $out/bin/
65 '';
66 };
67
68 installer = pkgs.stdenv.mkDerivation {
69 name = "shortwave-installer";
70 version = "1.0.0";
71 src = ./.;
72
73 nativeBuildInputs = with pkgs; [
74 nsis
75 ];
76
77 buildInputs = [ self'.packages.shortwave ];
78 buildPhase = ''
79 # Create staging directory
80 mkdir -p staging
81
82 # Copy executable and DLLs
83 cp ${self'.packages.shortwave}/bin/Shortwave.exe staging/
84
85 cp libs/bass.dll staging/
86
87 cp shortwave.ico staging/
88
89 # Copy documentation
90 cp LICENSE.md staging/
91 cp README.md staging/
92
93 # Build installer
94 cd staging
95 makensis -NOCD ../installer.nsi
96
97 # Rename output to expected installer name
98 if [ -f ShortwaveRadioInstaller.exe ]; then
99 mv ShortwaveRadioInstaller.exe ../
100 else
101 echo "✗ Installer was not created by makensis"
102 exit 1
103 fi
104 cd ..
105 ls
106 '';
107
108 installPhase = ''
109 mkdir -p $out/bin
110 cp ShortwaveRadioInstaller.exe $out/bin/
111 '';
112 };
113
114 deploy-to-xp = pkgs.writeShellScriptBin "deploy-to-xp" ''
115 echo "rebuilding program"
116 nix build
117
118 XP_DIR="$HOME/Documents/xp-drive"
119 mkdir -p "$XP_DIR"
120
121 echo "Deploying Shortwave Radio to $XP_DIR..."
122
123 # Copy executable with force overwrite
124 if cp -f result/bin/Shortwave.exe "$XP_DIR/"; then
125 echo "✓ Copied Shortwave.exe"
126 else
127 echo "✗ Failed to copy Shortwave.exe"
128 exit 1
129 fi
130
131 # Copy BASS DLL from libs directory
132 if [ -f libs/bass.dll ]; then
133 if cp -f libs/bass.dll "$XP_DIR/"; then
134 echo "✓ Copied bass.dll"
135 else
136 echo "✗ Failed to copy bass.dll"
137 exit 1
138 fi
139 else
140 echo "⚠ bass.dll not found in libs/ directory - BASS audio will not work"
141 fi
142
143 echo "🎵 Shortwave Radio deployed successfully!"
144 echo "Files in XP directory:"
145 ls -la "$XP_DIR"/*.{exe,dll} 2>/dev/null || echo "No files found"
146 '';
147
148 build-installer = pkgs.writeShellScriptBin "build-installer" ''
149 echo "Building Shortwave Radio installer..."
150 nix build .#installer
151
152 if [ -f result/bin/ShortwaveRadioInstaller.exe ]; then
153 echo "✓ Installer built successfully: result/bin/ShortwaveRadioInstaller.exe"
154 ls -la result/bin/ShortwaveRadioInstaller.exe
155 else
156 echo "✗ Installer build failed"
157 exit 1
158 fi
159 '';
160
161 default = self'.packages.shortwave;
162 };
163
164 devShells = {
165 default = pkgs.mkShell {
166 buildInputs = with pkgs; [
167 cmake
168 pkgsCross.mingw32.buildPackages.gcc
169 self'.packages.deploy-to-xp
170 self'.packages.build-installer
171 nsis
172 ];
173
174 shellHook = ''
175 echo "Shortwave Radio development environment loaded"
176 echo "Available commands:"
177 echo " nix build - Build the Shortwave Radio application"
178 echo " nix build .#installer - Build Windows installer"
179 echo " build-installer - Build installer (shortcut)"
180 echo " deploy-to-xp - Deploy to XP VM folder"
181 echo ""
182 echo "Setting up development environment..."
183
184 # Get dynamic paths from nix packages
185 GCC_BASE="${pkgs.pkgsCross.mingw32.buildPackages.gcc}/i686-w64-mingw32"
186 SYS_INCLUDE="$GCC_BASE/sys-include"
187 MINGW_MAIN_INCLUDE="${pkgs.pkgsCross.mingw32.windows.mingw_w64.dev}/include"
188 CPP_INCLUDE="${pkgs.lib.getDev pkgs.pkgsCross.mingw32.buildPackages.gcc}/include/c++/10.3.0"
189 CPP_TARGET_INCLUDE="$CPP_INCLUDE/i686-w64-mingw32"
190
191 # Auto-generate .clangd config with correct paths
192 cat > .clangd << EOF
193 CompileFlags:
194 Add:
195 - -target
196 - i686-w64-mingw32
197 - -DWINVER=0x0501
198 - -D_WIN32_WINNT=0x0501
199 - -DWIN32_LEAN_AND_MEAN
200 - -D_WIN32
201 - -DWIN32
202 - -std=c++17
203 - -fno-builtin
204 - -isystem
205 - $SYS_INCLUDE
206 - -isystem
207 - $MINGW_MAIN_INCLUDE
208 - -isystem
209 - $CPP_INCLUDE
210 - -isystem
211 - $CPP_TARGET_INCLUDE
212 Remove:
213 - -I*/gcc/*/include
214 EOF
215
216 cat > compile_commands.json << EOF
217 [
218 {
219 "directory": "$(pwd)",
220 "command": "i686-w64-mingw32-g++ -DWINVER=0x0501 -D_WIN32_WINNT=0x0501 -DWIN32_LEAN_AND_MEAN -D_WIN32 -DWIN32 -std=c++17 -isystem \"$SYS_INCLUDE\" -isystem \"$MINGW_MAIN_INCLUDE\" -isystem \"$CPP_INCLUDE\" -isystem \"$CPP_TARGET_INCLUDE\" -c main.cpp",
221 "file": "main.cpp"
222 }
223 ]
224 EOF
225
226 echo "✓ Generated .clangd config and compile_commands.json with include paths"
227 echo "✓ Development environment ready for Shortwave Radio development"
228 '';
229 };
230 };
231 };
232 };
233}