+/tetris
my tetris implementation
git clone https://git.julia.blue/+/tetris
19928ec
change-origin
1{ 2description = "tetris and related tools" ; 3inputs = { 4nixpkgs . url = "github:NixOS/nixpkgs/nixpkgs-unstable" ; 5flake-utils . url = "github:numtide/flake-utils" ; 6crane . url = "github:ipetkov/crane" ; 7rust-overlay . url = "github:oxalica/rust-overlay" ; 8rust-overlay . inputs . nixpkgs . follows = "nixpkgs" ; 9}; 10 11outputs = { self , nixpkgs , flake-utils , crane , rust-overlay , ...} : 12flake-utils . lib . eachDefaultSystem ( system :let 13pkgs = import nixpkgs { 14inherit system ; 15overlays = [ ( import rust-overlay ) ]; 16}; 17craneLib = ( crane . mkLib pkgs ). overrideToolchain ( p : 18p . rust-bin . stable . latest . default ); 19inherit ( pkgs ) lib ; 20 21darwinArgs = { 22# `coreaudio-sys` calls `bindgen` at build time _always_ 😞 23LIBCLANG_PATH = " ${ pkgs . llvmPackages . libclang . lib } /lib" ; 24 25# `coreaudio-sys` expects the headers for this packages to be available 26# in a directory structure matching the MacOS SDKs. 27# 28# If we don't set this env var, `coreaudio-sys` will ask `xcrun` for the 29# MacOS SDK path and the nix `xcrun` wrapper just points to a stub SDK 30# without any frameworks or headers: https://github.com/NixOS/nixpkgs/blob/bcf1085724f62e860f2cddd2c6eaee7dceb22888/pkgs/development/tools/xcbuild/wrapper.nix#L54 31# 32# See: 33# - https://discourse.nixos.org/t/develop-shell-environment-setup-for-macos/11399/6 34# - https://github.com/RustAudio/coreaudio-sys/blob/8185e0704754a0d3e3c41e9557d24f5f406ce5ef/build.rs#L6 35COREAUDIO_SDK_PATH = pkgs . symlinkJoin { 36name = "sdk" ; 37# See: https://github.com/RustAudio/coreaudio-sys/blob/8185e0704754a0d3e3c41e9557d24f5f406ce5ef/build.rs#L50-L102 38paths = with pkgs . darwin . apple_sdk . frameworks ; 39[ AudioToolbox AudioUnit CoreAudio CoreFoundation CoreMIDI OpenAL ]; 40postBuild = '' 41mkdir $ out /System 42mv $ out /Library $ out /System 43'' ; 44}; 45}; 46 47addBindgenEnvVar = base :base . overrideAttrs ( old :{ 48# (the above fixes for the macOS framework paths do not seem to be 49# enough anymore; poking at `cbindgen` reveals that it now seems to 50# "sanitize" our NIX_CFLAGS_COMPILE injected `-iframework` includes 51# and turn them into regular `-isystem` includes, breaking 52# framework headers. to get around this we use the inelegant 53# "big hammer" solution below: forcibly reintroducing our 54# `-iframework` flags to `cbindgen`'s list of flags passed to 55# `libclang`): 56preBuild = ( old . preBuild or "" ) + 57pkgs . lib . optionalString ( pkgs . stdenv . isDarwin ) '' 58export BINDGEN_EXTRA_CLANG_ARGS="$NIX_CFLAGS_COMPILE" 59'' ; 60}); 61 62src = craneLib . cleanCargoSource ./. ; 63 64commonArgs = { 65inherit src ; 66strictDeps = true ; 67 68nativeBuildInputs = lib . optionals pkgs . stdenv . isLinux ( with pkgs ; [ 69pkg-config makeWrapper alsa-lib openssl 70]); 71 72buildInputs = with pkgs ; [ libiconv ] ++ 73( lib . optional ( stdenv . isLinux ) alsa-lib ) ++ 74( lib . optionals ( stdenv . isDarwin ) 75( with darwin . apple_sdk . frameworks ; [ AudioUnit CoreAudio pkgs . xcbuild ])); 76} // ( pkgs . lib . optionalAttrs ( pkgs . stdenv . isDarwin ) darwinArgs ); 77 78cargoArtifacts = addBindgenEnvVar ( craneLib . buildDepsOnly commonArgs ); 79 80tetris = craneLib . buildPackage ( commonArgs // { 81inherit cargoArtifacts ; 82doCheck = false ; # there's a separate check for that 83} // ( pkgs . lib . optionalAttrs ( pkgs . stdenv . isLinux ) { 84postInstall = '' 85wrapProgram $ out /bin/tetris \ 86--set-default "ALSA_PLUGIN_DIR" " ${ pkgs . alsa-plugins } /lib/alsa-lib " 87'' ; 88})); 89 90# jstrisSprint = pkgs.writeShellApplication { 91# name = "jstris-sprint"; 92# runtimeInputs = jjstrisScriptDeps; 93# text = ./jstris-sprint.sh; 94# }; 95 96jstrisScriptDeps = with pkgs ; [ 97xh pup jq bc sd choose moreutils gnuplot 98( python3 . withPackages ( pp :with pp ;[ matplotlib ])) 99]; 100 101in { 102packages . default = tetris ; 103 104checks = { 105build = tetris ; 106test = craneLib . cargoNextest ( commonArgs // { inherit cargoArtifacts ; }); 107clippy = addBindgenEnvVar ( craneLib . cargoClippy ( commonArgs // { 108inherit cargoArtifacts ; 109cargoClippyExtraArgs = "--all-targets -- --deny warnings" ; 110})); 111doc = craneLib . cargoDoc ( commonArgs // { inherit cargoArtifacts ; }); 112fmt = craneLib . cargoFmt { inherit src ; }; 113toml-fmt = craneLib . taploFmt { 114src = pkgs . lib . sources . sourceFilesBySuffices src [ ".toml" ]; 115}; 116}; 117 118devShells . default = craneLib . devShell { 119inputsFrom = [ tetris ]; 120checks = self . checks .${ system }; 121packages = with pkgs ; [ rust-analyzer ] ++ jstrisScriptDeps ; 122}; 123} 124); 125}