From d80949932c05a4001b217b2bdf12fa6416fa49df Mon Sep 17 00:00:00 2001
From: ryoppippi <1560508+ryoppippi@users.noreply.github.com>
Date: Mon, 7 Oct 2024 11:01:11 +0100
Subject: [PATCH 1/9] fix(flake.nix): add `SystemConfiguration` for Darwin

---
 flake.nix | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flake.nix b/flake.nix
index dccdd6c..2b4600f 100644
--- a/flake.nix
+++ b/flake.nix
@@ -17,7 +17,7 @@
           openssl
           dbus
           sqlite
-        ] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security ];
+        ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Security SystemConfiguration ]);
 
 
         package = with pkgs; rustPlatform.buildRustPackage rec {

From 481d723afe284e791677aa3b747e259459989e03 Mon Sep 17 00:00:00 2001
From: ryoppippi <1560508+ryoppippi@users.noreply.github.com>
Date: Mon, 7 Oct 2024 13:40:39 +0100
Subject: [PATCH 2/9] style(flake.nix): fix inputs style

---
 flake.nix | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/flake.nix b/flake.nix
index 2b4600f..1b2a263 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,8 +1,10 @@
 {
   description = "Leet your code in command-line.";
 
-  inputs.nixpkgs.url      = "github:NixOS/nixpkgs/nixpkgs-unstable";
-  inputs.utils.url        = "github:numtide/flake-utils";
+  inputs = {
+    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+    utils.url = "github:numtide/flake-utils";
+  };
 
   outputs = { self, nixpkgs, utils, ... }:
     utils.lib.eachDefaultSystem (system:
@@ -22,12 +24,8 @@
 
         package = with pkgs; rustPlatform.buildRustPackage rec {
           pname = "leetcode-cli";
-          version = "0.4.3";
-          src = fetchCrate {
-            inherit pname version;
-            sha256 = "sha256-y5zh93WPWSMDXqYangqrxav+sC0b0zpFIp6ZIew6KMo=";
-          };
-          cargoSha256 = "sha256-VktDiLsU+GOsa6ba9JJZGEPTavSKp+aSZm2dfhPEqMs=";
+          version = "git";
+          src = ./.;
 
           inherit buildInputs nativeBuildInputs;
 
@@ -46,7 +44,7 @@
           };
         };
       in
-      {
+        {
         defaultPackage = package;
         overlay = final: prev: { leetcode-cli = package; };
 

From c22c6339fa8362b7c07a6a6175aa0dcab1364cac Mon Sep 17 00:00:00 2001
From: ryoppippi <1560508+ryoppippi@users.noreply.github.com>
Date: Mon, 7 Oct 2024 13:41:16 +0100
Subject: [PATCH 3/9] feat(flake.nix): add naersk as an input

---
 flake.nix | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/flake.nix b/flake.nix
index 1b2a263..11f28db 100644
--- a/flake.nix
+++ b/flake.nix
@@ -4,6 +4,12 @@
   inputs = {
     nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
     utils.url = "github:numtide/flake-utils";
+
+    naersk = {
+      url = "github:nix-community/naersk";
+      inputs.nixpkgs.follows = "nixpkgs";
+    };
+
   };
 
   outputs = { self, nixpkgs, utils, ... }:

From fdd99ad1454ee25c1f66cffe7909232cb6a036a1 Mon Sep 17 00:00:00 2001
From: ryoppippi <1560508+ryoppippi@users.noreply.github.com>
Date: Mon, 7 Oct 2024 13:48:06 +0100
Subject: [PATCH 4/9] feat(flake.nix): rust-overlay

---
 flake.nix | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/flake.nix b/flake.nix
index 11f28db..6e25afa 100644
--- a/flake.nix
+++ b/flake.nix
@@ -10,9 +10,14 @@
       inputs.nixpkgs.follows = "nixpkgs";
     };
 
+    rust-overlay = {
+      url = "github:oxalica/rust-overlay";
+      inputs = {
+        nixpkgs.follows = "nixpkgs";
+      };
+    };
   };
 
-  outputs = { self, nixpkgs, utils, ... }:
     utils.lib.eachDefaultSystem (system:
       let
         pkgs = import nixpkgs { inherit system; };

From e1760deda7f23e03302a0a79b44642ebe80d4266 Mon Sep 17 00:00:00 2001
From: ryoppippi <1560508+ryoppippi@users.noreply.github.com>
Date: Mon, 7 Oct 2024 13:58:35 +0100
Subject: [PATCH 5/9] feat(rust-toolchain.toml): define toolchaines

---
 rust-toolchain.toml | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 rust-toolchain.toml

diff --git a/rust-toolchain.toml b/rust-toolchain.toml
new file mode 100644
index 0000000..7ae198f
--- /dev/null
+++ b/rust-toolchain.toml
@@ -0,0 +1,10 @@
+[toolchain]
+channel = "nightly"
+components = [
+  "rustc",
+  "cargo",
+  "rustfmt",
+  "clippy",
+  "rust-analyzer",
+]
+profile = "minimal"

From 21c2b45bb986524b968ad443092dc0c1a1fee771 Mon Sep 17 00:00:00 2001
From: ryoppippi <1560508+ryoppippi@users.noreply.github.com>
Date: Mon, 7 Oct 2024 14:43:09 +0100
Subject: [PATCH 6/9] feat(flake.nix): rewrite with naersk

https://github.com/nix-community/naersk
---
 flake.lock          | 42 +++++++++++++++++++++++++++++++++++
 flake.nix           | 53 ++++++++++++++++++++++++++++++++++-----------
 rust-toolchain.toml |  2 +-
 3 files changed, 83 insertions(+), 14 deletions(-)

diff --git a/flake.lock b/flake.lock
index a62c24a..de27928 100644
--- a/flake.lock
+++ b/flake.lock
@@ -1,5 +1,25 @@
 {
   "nodes": {
+    "naersk": {
+      "inputs": {
+        "nixpkgs": [
+          "nixpkgs"
+        ]
+      },
+      "locked": {
+        "lastModified": 1721727458,
+        "narHash": "sha256-r/xppY958gmZ4oTfLiHN0ZGuQ+RSTijDblVgVLFi1mw=",
+        "owner": "nix-community",
+        "repo": "naersk",
+        "rev": "3fb418eaf352498f6b6c30592e3beb63df42ef11",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-community",
+        "repo": "naersk",
+        "type": "github"
+      }
+    },
     "nixpkgs": {
       "locked": {
         "lastModified": 1703499205,
@@ -18,10 +38,32 @@
     },
     "root": {
       "inputs": {
+        "naersk": "naersk",
         "nixpkgs": "nixpkgs",
+        "rust-overlay": "rust-overlay",
         "utils": "utils"
       }
     },
+    "rust-overlay": {
+      "inputs": {
+        "nixpkgs": [
+          "nixpkgs"
+        ]
+      },
+      "locked": {
+        "lastModified": 1728268235,
+        "narHash": "sha256-lJMFnMO4maJuNO6PQ5fZesrTmglze3UFTTBuKGwR1Nw=",
+        "owner": "oxalica",
+        "repo": "rust-overlay",
+        "rev": "25685cc2c7054efc31351c172ae77b21814f2d42",
+        "type": "github"
+      },
+      "original": {
+        "owner": "oxalica",
+        "repo": "rust-overlay",
+        "type": "github"
+      }
+    },
     "systems": {
       "locked": {
         "lastModified": 1681028828,
diff --git a/flake.nix b/flake.nix
index 6e25afa..e702724 100644
--- a/flake.nix
+++ b/flake.nix
@@ -18,33 +18,57 @@
     };
   };
 
+  outputs = {
+    self,
+    nixpkgs,
+    utils,
+    naersk,
+    rust-overlay,
+    ...
+    }:
     utils.lib.eachDefaultSystem (system:
       let
-        pkgs = import nixpkgs { inherit system; };
+        overlays = [ (import rust-overlay) ];
+
+        pkgs = (import nixpkgs) {
+          inherit system overlays;
+        };
+
+        toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
+
+        naersk' = pkgs.callPackage naersk {
+          cargo = toolchain;
+          rustc = toolchain;
+          clippy = toolchain;
+        };
 
         nativeBuildInputs = with pkgs; [
           pkg-config
         ];
 
+        darwinBuildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin [
+          pkgs.darwin.apple_sdk.frameworks.Security
+          pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
+        ];
+
         buildInputs = with pkgs; [
           openssl
           dbus
           sqlite
-        ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Security SystemConfiguration ]);
-
+        ] ++ darwinBuildInputs;
 
-        package = with pkgs; rustPlatform.buildRustPackage rec {
+        package = naersk'.buildPackage rec {
           pname = "leetcode-cli";
           version = "git";
+
           src = ./.;
+          doCheck = true; # run `cargo test` on build
 
           inherit buildInputs nativeBuildInputs;
 
-          # a nightly compiler is required unless we use this cheat code.
-          RUSTC_BOOTSTRAP = 0;
+          buildNoDefaultFeatures = true;
 
-          # CFG_RELEASE = "${rustPlatform.rust.rustc.version}-stable";
-          CFG_RELEASE_CHANNEL = "stable";
+          buildFeatures = "git";
 
           meta = with pkgs.lib; {
             description = "Leet your code in command-line.";
@@ -53,6 +77,13 @@
             maintainers = with maintainers; [ congee ];
             mainProgram = "leetcode";
           };
+
+          # Env vars
+          # a nightly compiler is required unless we use this cheat code.
+          RUSTC_BOOTSTRAP = 0;
+
+          # CFG_RELEASE = "${rustPlatform.rust.rustc.version}-stable";
+          CFG_RELEASE_CHANNEL = "stable";
         };
       in
         {
@@ -64,11 +95,7 @@
           inherit nativeBuildInputs;
 
           buildInputs = buildInputs ++ [
-            rustc
-            cargo
-            rustfmt
-            clippy
-            rust-analyzer
+            toolchain
             cargo-edit
             cargo-bloat
             cargo-audit
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
index 7ae198f..2a19081 100644
--- a/rust-toolchain.toml
+++ b/rust-toolchain.toml
@@ -1,5 +1,5 @@
 [toolchain]
-channel = "nightly"
+channel = "stable"
 components = [
   "rustc",
   "cargo",

From 12f9f1dd7e55f0d89d43284ec4a687b6652abf69 Mon Sep 17 00:00:00 2001
From: ryoppippi <1560508+ryoppippi@users.noreply.github.com>
Date: Sat, 12 Oct 2024 11:37:13 +0100
Subject: [PATCH 7/9] style(flake.nix): make it one line

---
 flake.nix | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/flake.nix b/flake.nix
index e702724..936e777 100644
--- a/flake.nix
+++ b/flake.nix
@@ -12,9 +12,7 @@
 
     rust-overlay = {
       url = "github:oxalica/rust-overlay";
-      inputs = {
-        nixpkgs.follows = "nixpkgs";
-      };
+      inputs.nixpkgs.follows = "nixpkgs";
     };
   };
 

From bdb58b7851fc1b6db8949f62e881997fe778692d Mon Sep 17 00:00:00 2001
From: ryoppippi <1560508+ryoppippi@users.noreply.github.com>
Date: Sat, 12 Oct 2024 11:41:03 +0100
Subject: [PATCH 8/9] chore(flake.lock): update

---
 flake.lock | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/flake.lock b/flake.lock
index de27928..8d2d0df 100644
--- a/flake.lock
+++ b/flake.lock
@@ -22,11 +22,11 @@
     },
     "nixpkgs": {
       "locked": {
-        "lastModified": 1703499205,
-        "narHash": "sha256-lF9rK5mSUfIZJgZxC3ge40tp1gmyyOXZ+lRY3P8bfbg=",
+        "lastModified": 1728538411,
+        "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=",
         "owner": "NixOS",
         "repo": "nixpkgs",
-        "rev": "e1fa12d4f6c6fe19ccb59cac54b5b3f25e160870",
+        "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221",
         "type": "github"
       },
       "original": {
@@ -51,11 +51,11 @@
         ]
       },
       "locked": {
-        "lastModified": 1728268235,
-        "narHash": "sha256-lJMFnMO4maJuNO6PQ5fZesrTmglze3UFTTBuKGwR1Nw=",
+        "lastModified": 1728700003,
+        "narHash": "sha256-Ox1pvEHxLK6lAdaKQW21Zvk65SPDag+cD8YA444R/og=",
         "owner": "oxalica",
         "repo": "rust-overlay",
-        "rev": "25685cc2c7054efc31351c172ae77b21814f2d42",
+        "rev": "fc1e58ebabe0cef4442eedea07556ff0c9eafcfe",
         "type": "github"
       },
       "original": {
@@ -84,11 +84,11 @@
         "systems": "systems"
       },
       "locked": {
-        "lastModified": 1701680307,
-        "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
+        "lastModified": 1726560853,
+        "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
         "owner": "numtide",
         "repo": "flake-utils",
-        "rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
+        "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
         "type": "github"
       },
       "original": {

From 9f6764d7cb5b5e92886798fa69cc9868ae2a5bc3 Mon Sep 17 00:00:00 2001
From: ryoppippi <1560508+ryoppippi@users.noreply.github.com>
Date: Sat, 12 Oct 2024 11:59:16 +0100
Subject: [PATCH 9/9] chore(gitignore): ignore nix result directory

---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index d97f62e..67e0e9c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
 .DS_Store
 .idea
 .direnv/
+/result