From 2f8255e336dc5fb093180ee683231a1490f2cb34 Mon Sep 17 00:00:00 2001
From: tracer-ysyx <tracer@ysyx.org>
Date: Thu, 11 Jan 2024 16:16:42 +0800
Subject: [PATCH] =?UTF-8?q?>=20compile=20NEMU=20ysyx=5F22040000=20?=
 =?UTF-8?q?=E6=9D=8E=E5=BF=83=E6=9D=A8=20Linux=20calcite=206.1.69=20#1-Nix?=
 =?UTF-8?q?OS=20SMP=20PREEMPT=5FDYNAMIC=20Wed=20Dec=2020=2016:00:29=20UTC?=
 =?UTF-8?q?=202023=20x86=5F64=20GNU/Linux=20=2016:16:42=20=20up=203=20days?=
 =?UTF-8?q?=2015:17,=20=202=20users,=20=20load=20average:=200.88,=200.74,?=
 =?UTF-8?q?=200.68?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 nemu/flake.lock                        | 82 ++++++++++++++++++++++++++
 nemu/flake.nix                         | 61 +++++++++++++++++++
 npc/core/src/test/scala/Keyboard.scala | 10 ----
 3 files changed, 143 insertions(+), 10 deletions(-)
 create mode 100644 nemu/flake.lock
 create mode 100644 nemu/flake.nix

diff --git a/nemu/flake.lock b/nemu/flake.lock
new file mode 100644
index 0000000..5c64744
--- /dev/null
+++ b/nemu/flake.lock
@@ -0,0 +1,82 @@
+{
+  "nodes": {
+    "flake-utils": {
+      "inputs": {
+        "systems": "systems"
+      },
+      "locked": {
+        "lastModified": 1701680307,
+        "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
+        "type": "github"
+      },
+      "original": {
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "type": "github"
+      }
+    },
+    "nixpkgs": {
+      "locked": {
+        "lastModified": 1704722960,
+        "narHash": "sha256-mKGJ3sPsT6//s+Knglai5YflJUF2DGj7Ai6Ynopz0kI=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "317484b1ead87b9c1b8ac5261a8d2dd748a0492d",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "nixos-unstable",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "nur-xin": {
+      "inputs": {
+        "nixpkgs": [
+          "nixpkgs"
+        ]
+      },
+      "locked": {
+        "lastModified": 1704680562,
+        "narHash": "sha256-ffec3HL8OgbHB/TvLHILvC3ylou6N+KDtrn4qYVV+U4=",
+        "ref": "refs/heads/master",
+        "rev": "8adf33b6fdd113c645d83feda28622a0b1ef9f83",
+        "revCount": 144,
+        "type": "git",
+        "url": "https://git.xinyang.life/xin/nur.git"
+      },
+      "original": {
+        "type": "git",
+        "url": "https://git.xinyang.life/xin/nur.git"
+      }
+    },
+    "root": {
+      "inputs": {
+        "flake-utils": "flake-utils",
+        "nixpkgs": "nixpkgs",
+        "nur-xin": "nur-xin"
+      }
+    },
+    "systems": {
+      "locked": {
+        "lastModified": 1681028828,
+        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+        "owner": "nix-systems",
+        "repo": "default",
+        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-systems",
+        "repo": "default",
+        "type": "github"
+      }
+    }
+  },
+  "root": "root",
+  "version": 7
+}
diff --git a/nemu/flake.nix b/nemu/flake.nix
new file mode 100644
index 0000000..5c933c0
--- /dev/null
+++ b/nemu/flake.nix
@@ -0,0 +1,61 @@
+{
+  inputs = {
+    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+    flake-utils.url = "github:numtide/flake-utils";
+    nur-xin = {
+      url = "git+https://git.xinyang.life/xin/nur.git";
+      inputs.nixpkgs.follows = "nixpkgs";
+    };
+  };
+
+  outputs = { self, ... }@inputs: with inputs;
+    flake-utils.lib.eachDefaultSystem (system:
+      let
+        pkgs = nixpkgs.legacyPackages.${system} //
+          { nur.xin = nur-xin.legacyPackages.${system}; };
+      in
+      {
+        devShells.default = with pkgs; mkShell {
+          packages = [
+            clang-tools
+            rnix-lsp
+
+            gdb
+            jre
+
+            gtkwave
+          ];
+
+          inputsFrom = [ self.packages.${system}.default ];
+        };
+
+        packages.default = with pkgs; stdenv.mkDerivation rec {
+          pname = "nemu";
+          version = "2024-01-02";
+
+          src = ./.;
+
+          nativeBuildInputs = [
+            gnumake
+            flex
+            bison
+          ];
+
+          buildInputs = [
+            readline
+            libllvm
+          ];
+
+          NEMU_HOME = src;
+
+          meta = with lib; {
+            description = "NJU EMUlator, a full system x86/mips32/riscv32/riscv64 emulator for teaching";
+            homepage = "https://github.com/NJU-ProjectN/nemu.git";
+            license = with licenses; [ ];
+            maintainers = with maintainers; [ ];
+          };
+        };
+      }
+    );
+}
+
diff --git a/npc/core/src/test/scala/Keyboard.scala b/npc/core/src/test/scala/Keyboard.scala
index 24723cc..92ecadb 100644
--- a/npc/core/src/test/scala/Keyboard.scala
+++ b/npc/core/src/test/scala/Keyboard.scala
@@ -60,13 +60,3 @@ class KeyboardControllerSpec extends AnyFreeSpec with ChiselScalatestTester {
     }
   }
 }
-
-class SegSpec extends AnyFreeSpec with ChiselScalatestTester {
-  "try out vec" in {
-    test(new SegGenerator(8)) {c =>
-      c.io.keycode.bits.poke(0xAC)
-      c.clock.step(1)
-      println(s"out: ${c.io.segs(0).peek().litValue}")
-    }
-  }
-}