From 8185c731a68813d6387efb54560613fefebe142b Mon Sep 17 00:00:00 2001 From: aster <137767097+aster-void@users.noreply.github.com> Date: Wed, 15 Jan 2025 13:57:27 +0900 Subject: [PATCH 1/3] use rust-overlay, refac, and set rust version to stable --- flake.lock | 49 +++++++--------------- flake.nix | 83 ++++++++++++++++++++----------------- scraper/rust-toolchain.toml | 4 +- 3 files changed, 63 insertions(+), 73 deletions(-) diff --git a/flake.lock b/flake.lock index 1ea31523..aad9a49b 100644 --- a/flake.lock +++ b/flake.lock @@ -1,27 +1,5 @@ { "nodes": { - "fenix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" - }, - "locked": { - "lastModified": 1735713283, - "narHash": "sha256-xC6X49L55xo7AV+pAYclOj5UNWtBo/xx5aB5IehJD0M=", - "owner": "nix-community", - "repo": "fenix", - "rev": "bfba822a4220b0e2c4dc7f36a35e4c8450cd9a9c", - "type": "github" - }, - "original": { - "owner": "nix-community", - "ref": "monthly", - "repo": "fenix", - "type": "github" - } - }, "flake-utils": { "inputs": { "systems": "systems" @@ -58,25 +36,28 @@ }, "root": { "inputs": { - "fenix": "fenix", "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" } }, - "rust-analyzer-src": { - "flake": false, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, "locked": { - "lastModified": 1735659655, - "narHash": "sha256-DQgwi3pwaasWWDfNtXIX0lW5KvxQ+qVhxO1J7l68Qcc=", - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "085ad107943996c344633d58f26467b05f8e2ff0", + "lastModified": 1736907983, + "narHash": "sha256-fw55wVwpJW36Md2HZBKuxX3YHGeqsGsspPLtCMVr1Y8=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "eaa365c911441e07e387ff6acc596619fc50b156", "type": "github" }, "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", + "owner": "oxalica", + "repo": "rust-overlay", "type": "github" } }, diff --git a/flake.nix b/flake.nix index 85e717d4..12ec799c 100644 --- a/flake.nix +++ b/flake.nix @@ -6,51 +6,60 @@ # unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; - fenix = { - url = "github:nix-community/fenix/monthly"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; inputs.nixpkgs.follows = "nixpkgs"; }; }; - outputs = { nixpkgs, flake-utils, fenix, /* unstable, */ ... }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - # unstable-pkgs = unstable.legacyPackages.${system}; - rust-toolchain = import ./nix/rust-toolchain.nix { inherit fenix system; }; + outputs = { + nixpkgs, + flake-utils, + rust-overlay, + /* + unstable, + */ + ... + }: + flake-utils.lib.eachDefaultSystem (system: let + overlays = [(import rust-overlay)]; + pkgs = import nixpkgs { + inherit system overlays; + }; + # unstable-pkgs = unstable.legacyPackages.${system}; + rust-bin = pkgs.rust-bin.fromRustupToolchainFile ./scraper/rust-toolchain.toml; - common = { - buildInputs = with pkgs; [ - gnumake - bun - biome - lefthook - dotenv-cli - prisma - prisma-engines - ]; - - shellHook = with pkgs; '' - # requird by prisma - export PRISMA_QUERY_ENGINE_BINARY="${prisma-engines}/bin/query-engine"; - export PRISMA_QUERY_ENGINE_LIBRARY="${prisma-engines}/lib/libquery_engine.node"; - export PRISMA_INTROSPECTION_ENGINE_BINARY="${prisma-engines}/bin/introspection-engine"; - export PRISMA_FMT_BINARY="${prisma-engines}/bin/prisma-fmt"; + common = { + packages = with pkgs; [ + gnumake + bun + biome + lefthook + dotenv-cli + prisma + prisma-engines + stdenv.cc.cc.lib + ]; - export LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib - ''; + env = with pkgs; { + # requird by prisma + PRISMA_QUERY_ENGINE_BINARY = "${prisma-engines}/bin/query-engine"; + PRISMA_QUERY_ENGINE_LIBRARY = "${prisma-engines}/lib/libquery_engine.node"; + PRISMA_INTROSPECTION_ENGINE_BINARY = "${prisma-engines}/bin/introspection-engine"; + PRISMA_FMT_BINARY = "${prisma-engines}/bin/prisma-fmt"; }; - in - { - devShells.default = pkgs.mkShell common; - devShells.scraper = pkgs.mkShell { - buildInputs = common.buildInputs ++ [ + }; + in { + devShells.default = pkgs.mkShell common; + devShells.scraper = pkgs.mkShell { + inherit (common) env; + packages = + common.packages + ++ [ pkgs.pkg-config pkgs.openssl - rust-toolchain + rust-bin ]; - shellHook = common.shellHook; - }; - }); + }; + }); } - diff --git a/scraper/rust-toolchain.toml b/scraper/rust-toolchain.toml index 044314a7..215f1208 100644 --- a/scraper/rust-toolchain.toml +++ b/scraper/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.82.0" -targets = ["aarch64-apple-darwin", "x86_64-unknown-linux-gnu"] +channel = "stable" components = ["rustc", "cargo", "rustfmt", "clippy"] +targets = [] From 1f82d12dc3d3e5b0c3a914165165750a30ac197c Mon Sep 17 00:00:00 2001 From: aster <137767097+aster-void@users.noreply.github.com> Date: Wed, 15 Jan 2025 14:21:18 +0900 Subject: [PATCH 2/3] rename course-mate-scraper -> coursemate-scraper, and create default.nix that defines the crate --- .cspell.json | 4 +++- flake.nix | 1 + nix/rust-toolchain.nix | 5 ----- scraper/Cargo.lock | 4 ++-- scraper/Cargo.toml | 2 +- scraper/default.nix | 21 +++++++++++++++++++++ 6 files changed, 28 insertions(+), 9 deletions(-) delete mode 100644 nix/rust-toolchain.nix create mode 100644 scraper/default.nix diff --git a/.cspell.json b/.cspell.json index 7a3271c7..eea8b479 100644 --- a/.cspell.json +++ b/.cspell.json @@ -20,7 +20,9 @@ "safify", "supabase", "swiper", - "lefthook" + "lefthook", + "stdenv", + "rustc" ], "dictionaries": [ "softwareTerms", diff --git a/flake.nix b/flake.nix index 12ec799c..e3d03133 100644 --- a/flake.nix +++ b/flake.nix @@ -50,6 +50,7 @@ }; }; in { + packages.scraper = pkgs.callPackage ./scraper {toolchain = rust-bin;}; devShells.default = pkgs.mkShell common; devShells.scraper = pkgs.mkShell { inherit (common) env; diff --git a/nix/rust-toolchain.nix b/nix/rust-toolchain.nix deleted file mode 100644 index 5a919688..00000000 --- a/nix/rust-toolchain.nix +++ /dev/null @@ -1,5 +0,0 @@ -{ fenix, system }: -fenix.packages.${system}.fromToolchainFile { - file = ../scraper/rust-toolchain.toml; - sha256 = "sha256-yMuSb5eQPO/bHv+Bcf/US8LVMbf/G/0MSfiPwBhiPpk="; -} diff --git a/scraper/Cargo.lock b/scraper/Cargo.lock index 19fb391b..15fe7b20 100644 --- a/scraper/Cargo.lock +++ b/scraper/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -163,7 +163,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] -name = "course-mate-scraper" +name = "coursemate-scraper" version = "0.1.0" dependencies = [ "anyhow", diff --git a/scraper/Cargo.toml b/scraper/Cargo.toml index 1711fd0c..b30cb47c 100644 --- a/scraper/Cargo.toml +++ b/scraper/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "course-mate-scraper" +name = "coursemate-scraper" version = "0.1.0" edition = "2021" diff --git a/scraper/default.nix b/scraper/default.nix new file mode 100644 index 00000000..cbb6edf0 --- /dev/null +++ b/scraper/default.nix @@ -0,0 +1,21 @@ +{ + lib, + stdenv, + openssl, + pkg-config, + makeRustPlatform, + toolchain, +}: let + rustPlatform = makeRustPlatform { + cargo = toolchain; + rustc = toolchain; + }; +in + rustPlatform.buildRustPackage { + buildInputs = lib.lists.optional stdenv.isLinux openssl; + nativeBuildInputs = lib.lists.optional stdenv.isLinux pkg-config; + pname = "coursemate-scraper"; + version = "0.1.0"; + src = ./.; + cargoLock.lockFile = ./Cargo.lock; + } From 78be965a21390b9b25f6506178a399d8331b659a Mon Sep 17 00:00:00 2001 From: aster <137767097+aster-void@users.noreply.github.com> Date: Sun, 19 Jan 2025 14:45:31 +0900 Subject: [PATCH 3/3] add nodejs to dependencies --- README.md | 3 ++- flake.nix | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b8081128..598d7edb 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,8 @@ GNU Make が導入されています。以下は、ユーザーが使うこと - 以下をインストールします: - - Bun (js) + - Bun + - Node.js - GNU Make - nvm (optional) - lefthook diff --git a/flake.nix b/flake.nix index e3d03133..8543392e 100644 --- a/flake.nix +++ b/flake.nix @@ -33,11 +33,11 @@ packages = with pkgs; [ gnumake bun + nodejs-slim biome lefthook dotenv-cli prisma - prisma-engines stdenv.cc.cc.lib ];