From b3f2498c427fe665dbd22c7a9541f2a2f0ba3ed7 Mon Sep 17 00:00:00 2001 From: Xida Ren Date: Wed, 11 Sep 2024 16:03:21 -0700 Subject: [PATCH] finally nix building works --- flake.lock | 8 ++++---- flake.nix | 54 +++++++++++++++++++++++++++++------------------------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/flake.lock b/flake.lock index cbb9fa8..c7c4701 100644 --- a/flake.lock +++ b/flake.lock @@ -59,16 +59,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1725990404, - "narHash": "sha256-zjSZ0gH4d2EKfsAswZXtpNiTx4K47tFCyGFKspfv1tY=", + "lastModified": 1725983898, + "narHash": "sha256-4b3A9zPpxAxLnkF9MawJNHDtOOl6ruL0r6Og1TEDGCE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "aa2c4fc81bf56b380c21c502487bdf75ed51abe9", + "rev": "1355a0cbfeac61d785b7183c0caaec1f97361b43", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-unstable-small", + "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index 3a24bb5..1695fb8 100644 --- a/flake.nix +++ b/flake.nix @@ -1,9 +1,8 @@ { description = "Application packaged using poetry2nix"; - inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small"; poetry2nix = { url = "github:nix-community/poetry2nix"; inputs.nixpkgs.follows = "nixpkgs"; @@ -13,32 +12,37 @@ outputs = { self, nixpkgs, flake-utils, poetry2nix }: flake-utils.lib.eachDefaultSystem (system: let - # see https://github.com/nix-community/poetry2nix/tree/master#api for more functions and examples. pkgs = nixpkgs.legacyPackages.${system}; - inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication; - in - { - packages = { - chatsh = mkPoetryApplication { projectDir = self; }; - default = self.packages.${system}.chatsh; - }; + inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication defaultPoetryOverrides; - # Shell for app dependencies. - # - # nix develop - # - # Use this shell for developing your app. - devShells.default = pkgs.mkShell { - inputsFrom = [ self.packages.${system}.chatsh ]; + customOverrides = defaultPoetryOverrides.extend (self: super: { + # Add overrides only if the package exists in super + maturin = if super ? maturin then super.maturin.overridePythonAttrs (old: { + buildInputs = (old.buildInputs or []) ++ [ pkgs.rustc pkgs.cargo ]; + }) else null; + + tiktoken = if super ? tiktoken then super.tiktoken.overridePythonAttrs (old: { + buildInputs = (old.buildInputs or []) ++ [ self.setuptools-rust pkgs.rustc pkgs.cargo ]; + }) else null; + + pydantic-core = if super ? pydantic-core then super.pydantic-core.overridePythonAttrs (old: { + buildInputs = (old.buildInputs or []) ++ [ pkgs.rustc pkgs.cargo ]; + }) else null; + }); + + chatsh = mkPoetryApplication { + projectDir = ./.; + overrides = [ customOverrides ]; + preferWheels = true; }; - # Shell for poetry. - # - # nix develop .#poetry - # - # Use this shell for changes to pyproject.toml and poetry.lock. - devShells.poetry = pkgs.mkShell { + in { + packages.default = chatsh; + + devShells.default = pkgs.mkShell { + inputsFrom = [ chatsh ]; packages = [ pkgs.poetry ]; }; - }); -} + } + ); +} \ No newline at end of file