From 996408c83565d347618722d84c069a89a070f7e9 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Thu, 4 Jan 2024 23:00:03 +0800 Subject: [PATCH] nvboard: Init at 0.3 --- default.nix | 5 +++- flake.lock | 6 ++--- pkgs/nvboard/default.nix | 51 ++++++++++++++++++++++++++++++++++++++ pkgs/nvboard/fixpics.patch | 16 ++++++++++++ 4 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 pkgs/nvboard/default.nix create mode 100644 pkgs/nvboard/fixpics.patch diff --git a/default.nix b/default.nix index d6497c9..b9087ab 100644 --- a/default.nix +++ b/default.nix @@ -8,13 +8,16 @@ { pkgs ? import { } }: +with pkgs; + { # The `lib`, `modules`, and `overlay` names are special lib = import ./lib { inherit pkgs; }; # functions modules = import ./modules; # NixOS modules overlays = import ./overlays; # nixpkgs overlays - example-package = pkgs.callPackage ./pkgs/example-package { }; + example-package = callPackage ./pkgs/example-package { }; + nvboard = callPackage ./pkgs/nvboard { }; # some-qt5-package = pkgs.libsForQt5.callPackage ./pkgs/some-qt5-package { }; # ... } diff --git a/flake.lock b/flake.lock index a804412..0e3d3ae 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1624561540, - "narHash": "sha256-izJ2PYZMGMsSkg+e7c9A1x3t/yOLT+qzUM6WQsc2tqo=", + "lastModified": 1704161960, + "narHash": "sha256-QGua89Pmq+FBAro8NriTuoO/wNaUtugt29/qqA8zeeM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "c6a049a3d32293b24c0f894a840872cf67fd7c11", + "rev": "63143ac2c9186be6d9da6035fa22620018c85932", "type": "github" }, "original": { diff --git a/pkgs/nvboard/default.nix b/pkgs/nvboard/default.nix new file mode 100644 index 0000000..26b0f38 --- /dev/null +++ b/pkgs/nvboard/default.nix @@ -0,0 +1,51 @@ +{ stdenv +, fetchFromGitHub +, lib +, SDL2 +, SDL2_image +, python3 +}: + +stdenv.mkDerivation rec { + name = "nvboard"; + version = "0.3"; + src = fetchFromGitHub { + owner = "NJU-ProjectN"; + repo = "nvboard"; + rev = "23e79f86a6f915592cdf0af1c045a6f96082823c"; + hash = "sha256-/sC2XD19MVgwKJH/rdCsfewR/Yf7cyd9okQV/AErP+k="; + }; + patches = [ ./fixpics.patch ]; + + propagatedBuildInputs = [ + SDL2 + SDL2_image + ]; + + buildInputs = [ + python3 + ]; + + buildPhase = '' + export CXXFLAGS="-DNVBOARD_HOME=\\\"$out/share/nvboard\\\"" + echo $CXXFLAGS + make NVBOARD_HOME=$(pwd) -f ./scripts/nvboard.mk + ''; + + installPhase = '' + mkdir -p $out/lib + mkdir -p $out/include + mkdir -p $out/bin + mkdir -p $out/share/nvboard/pic + mkdir -p $out/share/nvboard/board + + cp ./build/nvboard.a $out/lib/libnvboard.a + cp ./include/* $out/include/ + cp ./pic/* $out/share/nvboard/pic + cp ./board/* $out/share/nvboard/board + + # Pin binding script + sed -i "s|os.environ.get('NVBOARD_HOME')|\"$out/share/nvboard\"|g" ./scripts/auto_pin_bind.py + install ./scripts/auto_pin_bind.py $out/bin/auto_pin_bind + ''; +} diff --git a/pkgs/nvboard/fixpics.patch b/pkgs/nvboard/fixpics.patch new file mode 100644 index 0000000..b89cc22 --- /dev/null +++ b/pkgs/nvboard/fixpics.patch @@ -0,0 +1,16 @@ +diff --git a/src/nvboard.cpp b/src/nvboard.cpp +index ff6a75c..3759ff7 100644 +--- a/src/nvboard.cpp ++++ b/src/nvboard.cpp +@@ -82,7 +82,11 @@ void nvboard_init(int vga_clk_cycle) { + 0 + ); + ++#ifdef NVBOARD_HOME ++ nvboard_home = NVBOARD_HOME; ++#else + nvboard_home = getenv("NVBOARD_HOME"); ++#endif + + load_background(main_renderer); + load_texture(main_renderer);