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