{ description = "Using Markdown Files to organize your life as a @Tag-Stream"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; pyproject-nix = { url = "github:pyproject-nix/pyproject.nix"; inputs.nixpkgs.follows = "nixpkgs"; }; uv2nix = { url = "github:pyproject-nix/uv2nix"; inputs.pyproject-nix.follows = "pyproject-nix"; inputs.nixpkgs.follows = "nixpkgs"; }; pyproject-build-systems = { url = "github:pyproject-nix/build-system-pkgs"; inputs.pyproject-nix.follows = "pyproject-nix"; inputs.uv2nix.follows = "uv2nix"; inputs.nixpkgs.follows = "nixpkgs"; }; git-hooks = { url = "github:cachix/git-hooks.nix"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { self, nixpkgs, pyproject-nix, uv2nix, pyproject-build-systems, git-hooks, ... }: let inherit (nixpkgs) lib; forAllSystems = lib.genAttrs lib.systems.flakeExposed; workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; }; overlay = workspace.mkPyprojectOverlay { sourcePreference = "wheel"; }; editableOverlay = workspace.mkEditablePyprojectOverlay { root = "$REPO_ROOT"; }; pythonSets = forAllSystems ( system: let pkgs = nixpkgs.legacyPackages.${system}; inherit (pkgs) stdenv; baseSet = pkgs.callPackage pyproject-nix.build.packages { python = pkgs.python313; }; pyprojectOverrides = _final: prev: { streamd = prev.streamd.overrideAttrs (old: { passthru = old.passthru // { tests = (old.passthru.tests or { }) // { pytest = stdenv.mkDerivation { name = "${_final.streamd.name}-pytest"; inherit (_final.streamd) src; nativeBuildInputs = [ (_final.mkVirtualEnv "streamd-pytest-env" { streamd = [ "dev" ]; }) ]; dontConfigure = true; buildPhase = '' runHook preBuild # Exit code 5 means no tests collected — allow it so the # check succeeds on an empty test suite. pytest || [ $? -eq 5 ] runHook postBuild ''; installPhase = '' runHook preInstall touch $out runHook postInstall ''; }; }; }; }); }; in baseSet.overrideScope ( lib.composeManyExtensions [ pyproject-build-systems.overlays.default overlay pyprojectOverrides ] ) ); mkGitHooksCheck = system: let pkgs = nixpkgs.legacyPackages.${system}; pythonSet = pythonSets.${system}; venv = pythonSet.mkVirtualEnv "streamd-check-env" workspace.deps.all; in git-hooks.lib.${system}.run { src = ./.; hooks = { basedpyright = { enable = true; entry = "${pkgs.basedpyright}/bin/basedpyright --pythonpath ${venv}/bin/python --project ${ pkgs.writeText "pyrightconfig.json" ( builtins.toJSON { reportMissingTypeStubs = false; reportUnnecessaryTypeIgnoreComment = false; } ) }"; files = "\\.py$"; types = [ "file" ]; }; ruff.enable = true; ruff-format.enable = true; commitizen.enable = true; }; }; in { packages = forAllSystems ( system: let pythonSet = pythonSets.${system}; pkgs = nixpkgs.legacyPackages.${system}; inherit (pkgs.callPackages pyproject-nix.build.util { }) mkApplication; in rec { streamd = mkApplication { venv = pythonSet.mkVirtualEnv "streamd-env" workspace.deps.default; package = pythonSet.streamd; }; default = streamd; } ); homeManagerModules.default = { lib, config, pkgs, ... }: let cfg = config.programs.streamd; in { options.programs.streamd = { enable = lib.mkEnableOption "streamd"; base-folder = lib.mkOption { type = lib.types.str; description = "Base Folder of streamd"; }; package = lib.mkOption { type = lib.types.package; default = self.packages.${pkgs.system}.streamd; defaultText = lib.literalExpression "inputs.streamd.packages.\${pkgs.system}.streamd"; description = "The package to use for the streamd binary."; }; }; config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "programs.streamd" pkgs lib.platforms.linux) ]; home.packages = [ cfg.package ]; xdg.configFile."streamd/config.yaml".source = (pkgs.formats.yaml { }).generate "streamd-configuration" { base_folder = cfg.base-folder; }; home.shellAliases.s = "streamd"; }; }; checks = forAllSystems ( system: let pythonSet = pythonSets.${system}; in { inherit (pythonSet.streamd.passthru.tests) pytest; pre-commit = mkGitHooksCheck system; } ); devShells = forAllSystems ( system: let pkgs = nixpkgs.legacyPackages.${system}; pythonSet = pythonSets.${system}.overrideScope editableOverlay; virtualenv = pythonSet.mkVirtualEnv "streamd-dev-env" workspace.deps.all; in { default = pkgs.mkShell { packages = [ virtualenv pkgs.uv ]; env = { UV_NO_SYNC = "1"; UV_PYTHON = pythonSet.python.interpreter; UV_PYTHON_DOWNLOADS = "never"; }; shellHook = '' unset PYTHONPATH export REPO_ROOT=$(git rev-parse --show-toplevel) ${(mkGitHooksCheck system).shellHook} ''; }; } ); }; }