Skip to content

Commit

Permalink
flake: use callPackage
Browse files Browse the repository at this point in the history
  • Loading branch information
kraanzu committed Nov 7, 2024
1 parent 130280b commit fcde37b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 84 deletions.
95 changes: 11 additions & 84 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
65 changes: 65 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -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";
};
}

0 comments on commit fcde37b

Please sign in to comment.