+/tetris

my tetris implementation

git clone https://git.julia.blue/+/tetris

Julia RyanCompress font7b6d6c0

main
4.2 KiB121 linesraw
1{
2  description = "tetris and related tools";
3  inputs = {
4    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5    flake-utils.url = "github:numtide/flake-utils";
6    crane.url = "github:ipetkov/crane";
7    rust-overlay.url = "github:oxalica/rust-overlay";
8    rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
9  };
10
11  outputs = { self, nixpkgs, flake-utils, crane, rust-overlay, ... }:
12    flake-utils.lib.eachDefaultSystem (system: let
13      pkgs = import nixpkgs {
14          inherit system;
15          overlays = [ (import rust-overlay) ];
16        };
17      craneLib = (crane.mkLib pkgs).overrideToolchain (p:
18        p.rust-bin.stable.latest.default.override {
19          targets = [ "wasm32-unknown-unknown" ];
20      });
21      inherit (pkgs) lib;
22
23      darwinArgs = {
24        # `coreaudio-sys` calls `bindgen` at build time _always_ 😞
25        LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib";
26        # might still need to set COREAUDIO_SDK_PATH to $SDK_ROOT?
27      };
28
29      addBindgenEnvVar = base: base.overrideAttrs (old: {
30          # (the above fixes for the macOS framework paths do not seem to be
31          # enough anymore; poking at `cbindgen` reveals that it now seems to
32          # "sanitize" our NIX_CFLAGS_COMPILE injected `-iframework` includes
33          # and turn them into regular `-isystem` includes, breaking
34          # framework headers. to get around this we use the inelegant
35          # "big hammer" solution below: forcibly reintroducing our
36          # `-iframework` flags to `cbindgen`'s list of flags passed to
37          # `libclang`):
38          preBuild = (old.preBuild or "") +
39            pkgs.lib.optionalString (pkgs.stdenv.isDarwin) ''
40              export BINDGEN_EXTRA_CLANG_ARGS="$NIX_CFLAGS_COMPILE"
41            '';
42      });
43
44      src = let
45        kdlFilter = path: _type: builtins.match ".*kdl$" path != null;
46        kdlOrCargo = path: type:
47          (kdlFilter path type) || (craneLib.filterCargoSources path type);
48      in lib.cleanSourceWith { src = ./.; filter = kdlOrCargo; name = "source"; };
49
50      commonArgs = {
51        inherit src;
52        strictDeps = true;
53
54        nativeBuildInputs = lib.optionals pkgs.stdenv.isLinux (with pkgs; [
55          pkg-config makeWrapper
56        ]);
57
58        buildInputs = with pkgs; [ libiconv openssl ] ++
59          (lib.optional (stdenv.isLinux) alsa-lib) ++
60          (lib.optional (stdenv.isDarwin) pkgs.xcbuild);
61      } // (pkgs.lib.optionalAttrs (pkgs.stdenv.isDarwin) darwinArgs);
62
63      cargoArtifacts = addBindgenEnvVar (craneLib.buildDepsOnly commonArgs);
64
65      tetris = craneLib.buildPackage (commonArgs // {
66        inherit cargoArtifacts;
67        doCheck = false; # there's a separate check for that
68      } // {
69        cargoExtraArgs = "-p tui";
70        postInstall = ''
71          mv $out/bin/tui $out/bin/tetris
72        '' + (pkgs.lib.optionalString (pkgs.stdenv.isLinux) ''
73          wrapProgram $out/bin/tetris \
74            --set-default "ALSA_PLUGIN_DIR" "${pkgs.alsa-plugins}/lib/alsa-lib"
75        '');
76      });
77
78      # jstrisSprint = pkgs.writeShellApplication {
79      #   name = "jstris-sprint";
80      #   runtimeInputs = jjstrisScriptDeps;
81      #   text = ./jstris-sprint.sh;
82      # };
83
84      jstrisScriptDeps = with pkgs; [
85        xh pup jq bc sd choose moreutils gnuplot
86        (python3.withPackages (pp: with pp;[matplotlib]))
87      ];
88
89    in {
90      packages.default = tetris;
91
92      checks = {
93        build = tetris;
94        test = craneLib.cargoNextest (commonArgs // {
95          inherit cargoArtifacts;
96          cargoNextestExtraArgs = "--workspace";
97        });
98        clippy = addBindgenEnvVar (craneLib.cargoClippy (commonArgs // {
99          inherit cargoArtifacts;
100          cargoClippyExtraArgs = "--all-targets --workspace -- --deny warnings";
101        }));
102        doc = craneLib.cargoDoc (commonArgs // {
103          inherit cargoArtifacts;
104          cargoDocExtraArgs = "--no-deps -p tetris";
105        });
106      };
107
108      devShells.default = craneLib.devShell {
109        inputsFrom = [ tetris ];
110        checks = self.checks.${system};
111        INTER="${pkgs.inter}/share/fonts/truetype/InterVariable.ttf";
112        packages = with pkgs; [
113          rust-analyzer
114          inter woff2
115          wasm-pack minify
116          static-web-server
117        ] ++ jstrisScriptDeps;
118      };
119    }
120  );
121}