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 deploy-to-xp = pkgs.writeShellScriptBin "deploy-to-xp" '' 69 echo "rebuilding program" 70 nix build 71 72 XP_DIR="$HOME/Documents/xp-drive" 73 mkdir -p "$XP_DIR" 74 75 echo "Deploying Shortwave Radio to $XP_DIR..." 76 77 # Copy executable with force overwrite 78 if cp -f result/bin/Shortwave.exe "$XP_DIR/"; then 79 echo " Copied Shortwave.exe" 80 else 81 echo " Failed to copy Shortwave.exe" 82 exit 1 83 fi 84 85 # Copy BASS DLL from libs directory 86 if [ -f libs/bass.dll ]; then 87 if cp -f libs/bass.dll "$XP_DIR/"; then 88 echo " Copied bass.dll" 89 else 90 echo " Failed to copy bass.dll" 91 exit 1 92 fi 93 else 94 echo " bass.dll not found in libs/ directory - BASS audio will not work" 95 fi 96 97 echo "🎵 Shortwave Radio deployed successfully!" 98 echo "Files in XP directory:" 99 ls -la "$XP_DIR"/*.{exe,dll} 2>/dev/null || echo "No files found" 100 ''; 101 102 build-installer = pkgs.writeShellScriptBin "build-installer" '' 103 echo "Building Shortwave Radio installer..." 104 nix build .#installer 105 106 if [ -f result/bin/ShortwaveRadioInstaller.exe ]; then 107 echo " Installer built successfully: result/bin/ShortwaveRadioInstaller.exe" 108 ls -la result/bin/ShortwaveRadioInstaller.exe 109 else 110 echo " Installer build failed" 111 exit 1 112 fi 113 ''; 114 115 default = self'.packages.shortwave; 116 }; 117 118 devShells = { 119 default = pkgs.mkShell { 120 buildInputs = with pkgs; [ 121 cmake 122 pkgsCross.mingw32.buildPackages.gcc 123 self'.packages.deploy-to-xp 124 self'.packages.build-installer 125 nsis 126 ]; 127 128 shellHook = '' 129 # Get dynamic paths from nix packages 130 GCC_BASE="${pkgs.pkgsCross.mingw32.buildPackages.gcc}/i686-w64-mingw32" 131 SYS_INCLUDE="$GCC_BASE/sys-include" 132 MINGW_MAIN_INCLUDE="${pkgs.pkgsCross.mingw32.windows.mingw_w64.dev}/include" 133 CPP_INCLUDE="${pkgs.lib.getDev pkgs.pkgsCross.mingw32.buildPackages.gcc}/include/c++/10.3.0" 134 CPP_TARGET_INCLUDE="$CPP_INCLUDE/i686-w64-mingw32" 135 136 # Auto-generate .clangd config with correct paths 137 cat > .clangd <<EOF 138 CompileFlags: 139 Add: 140 - -target 141 - i686-w64-mingw32 142 - -DWINVER=0x0501 143 - -D_WIN32_WINNT=0x0501 144 - -DWIN32_LEAN_AND_MEAN 145 - -D_WIN32 146 - -DWIN32 147 - -std=c++17 148 - -fno-builtin 149 - -isystem 150 - $SYS_INCLUDE 151 - -isystem 152 - $MINGW_MAIN_INCLUDE 153 - -isystem 154 - $CPP_INCLUDE 155 - -isystem 156 - $CPP_TARGET_INCLUDE 157 Remove: 158 - -I*/gcc/*/include 159 EOF 160 161 cat > compile_commands.json <<EOF 162 [ 163 { 164 "directory": "$(pwd)", 165 "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", 166 "file": "main.cpp" 167 } 168 ] 169 EOF 170 ''; 171 }; 172 }; 173 }; 174 }; 175}