From fcde37b62512a570f3b33f9b794d6f834061705f Mon Sep 17 00:00:00 2001 From: kraanzu Date: Thu, 7 Nov 2024 08:53:37 +0530 Subject: [PATCH] flake: use callPackage --- flake.nix | 95 ++++++------------------------------------------- nix/default.nix | 65 +++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 84 deletions(-) create mode 100644 nix/default.nix diff --git a/flake.nix b/flake.nix index 969b3472..0d271f71 100644 --- a/flake.nix +++ b/flake.nix @@ -1,104 +1,31 @@ { - description = "Flake for Dooit"; + description = "Flake for Dooit with default.nix integration"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; }; - outputs = inputs: let - # Define function to generate attributes for each system - forEachSystem = inputs.nixpkgs.lib.genAttrs inputs.nixpkgs.lib.platforms.all; + outputs = { + self, + nixpkgs, + ... + }: let + forEachSystem = nixpkgs.lib.genAttrs nixpkgs.lib.platforms.all; - # Import nixpkgs for each system pkgsFor = forEachSystem ( system: - import inputs.nixpkgs { + import nixpkgs { inherit system; } ); - # Common Python packages used in both main package and devShell - mainPkgs = python3: - with python3; [ - poetry-core - pyperclip - textual - pyyaml - dateutil - sqlalchemy - platformdirs - tzlocal - click - ]; - - # Additional packages for the devShell - devShellPkgs = python3: - with python3; [ - textual-dev - pre-commit-hooks - pytest - pytest-aio - faker - ]; - - # Native build inputs - nativeBuildInputs = pkgs: - with pkgs; [ - poetry - ]; - - # Define devShell for each system - devShellFor = system: - inputs.nixpkgs.lib.genAttrs ["default"] ( - _: - pkgsFor.${system}.mkShell { - buildInputs = - (mainPkgs pkgsFor.${system}.python312Packages) - ++ (devShellPkgs pkgsFor.${system}.python312Packages) - ++ [pkgsFor.${system}.bun]; - - shellHook = '' - cd site/ - ${pkgsFor.${system}.bun}/bin/bun install - cd .. - ''; - } - ); - - # Define default package for each system - defaultPackageFor = system: - pkgsFor.${system}.python312Packages.buildPythonPackage { - pname = "dooit"; - version = "3.0.0"; - src = ./.; - format = "pyproject"; - - nativeBuildInputs = nativeBuildInputs pkgsFor.${system}; - - pythonRelaxDeps = [ - "textual" - "tzlocal" - "platformdirs" - "sqlalchemy" - ]; - - buildInputs = mainPkgs pkgsFor.${system}.python312Packages; - propagatedBuildInputs = mainPkgs pkgsFor.${system}.python312Packages; - - doCheck = false; - }; + packageFor = system: + pkgsFor.${system}.callPackage ./nix {}; in { - # Define the devShells for each system - devShells = forEachSystem devShellFor; - - # Define the default package for each system packages = forEachSystem ( system: { - default = defaultPackageFor system; + default = packageFor system; } ); - - # Expose a top-level `defaultPackage` that detects the current system - defaultPackage = defaultPackageFor inputs.nixpkgs.lib.systems.defaultSystem; }; } diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 00000000..e784db89 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,65 @@ +{ + lib, + fetchFromGitHub, + dooit, + python311, + testers, + nix-update-script, +}: let + python3 = python311; +in + python3.pkgs.buildPythonApplication rec { + pname = "dooit"; + version = "3.0.0"; + pyproject = true; + + src = fetchFromGitHub { + owner = "kraanzu"; + repo = "dooit"; + rev = "develop"; # TODO: Change to version + hash = "sha256-N0r37iEj0P/qLBFG9bGPUPjw31Wk9kA+rrZd59Yrxd4="; + }; + + build-system = with python3.pkgs; [poetry-core]; + + pythonRelaxDeps = [ + "tzlocal" + "textual" + ]; + + propagatedBuildInputs = with python3.pkgs; [ + pyperclip + textual + pyyaml + dateutil + sqlalchemy + platformdirs + tzlocal + click + ]; + + # No tests available + doCheck = true; + + passthru = { + tests.version = testers.testVersion { + package = dooit; + command = "HOME=$(mktemp -d) dooit --version"; + }; + + updateScript = nix-update-script {}; + }; + + meta = with lib; { + description = "TUI todo manager"; + homepage = "https://github.com/kraanzu/dooit"; + changelog = "https://github.com/kraanzu/dooit/blob/develop/CHANGELOG.md"; # TODO: change to version + license = licenses.mit; + maintainers = with maintainers; [ + khaneliman + wesleyjrz + kraanzu + ]; + mainProgram = "dooit"; + }; + }