diff --git a/flake/outputs/templates.nix b/flake/outputs/templates.nix new file mode 100644 index 0000000..e739db0 --- /dev/null +++ b/flake/outputs/templates.nix @@ -0,0 +1,4 @@ +{ ... }: +{ + flake.templates = import ../../templates; +} diff --git a/templates/default.nix b/templates/default.nix new file mode 100644 index 0000000..e5e81a1 --- /dev/null +++ b/templates/default.nix @@ -0,0 +1,6 @@ +{ + "python-uv" = { + path = ./python-uv; + description = "a python project using uv"; + }; +} diff --git a/templates/python-uv/.envrc b/templates/python-uv/.envrc new file mode 100644 index 0000000..1425e08 --- /dev/null +++ b/templates/python-uv/.envrc @@ -0,0 +1,6 @@ +files=( + "uv.lock" + "pyproject.toml" +) +watch_file "${files[@]}" +use flake diff --git a/templates/python-uv/.gitignore b/templates/python-uv/.gitignore new file mode 100644 index 0000000..7dd3c2e --- /dev/null +++ b/templates/python-uv/.gitignore @@ -0,0 +1,14 @@ +result* +.direnv +.pre-commit-config.yaml + +# Python-generated files +__pycache__/ +*.py[oc] +build/ +dist/ +wheels/ +*.egg-info + +# Virtual environments +.venv diff --git a/templates/python-uv/README.md b/templates/python-uv/README.md new file mode 100644 index 0000000..e69de29 diff --git a/templates/python-uv/flake.nix b/templates/python-uv/flake.nix new file mode 100644 index 0000000..0b22919 --- /dev/null +++ b/templates/python-uv/flake.nix @@ -0,0 +1,108 @@ +{ + outputs = + inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + imports = [ + inputs.devshell.flakeModule + inputs.git-hooks-nix.flakeModule + inputs.treefmt-nix.flakeModule + ]; + perSystem = + { + config, + pkgs, + lib, + ... + }: + let + workspace = inputs.uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; }; + overlay = workspace.mkPyprojectOverlay { sourcePreference = "wheel"; }; + pyprojectOverrides = _final: _prev: { }; + pythonSet = + (pkgs.callPackage inputs.pyproject-nix.build.packages { + python = pkgs.python311; + }).overrideScope + (lib.composeExtensions overlay pyprojectOverrides); + in + { + devshells.default = { + packages = [ + (pythonSet.mkVirtualEnv "python-uv-env" workspace.deps.all) + pkgs.python311Packages.uv + config.treefmt.build.wrapper + ]; + env = [ + (lib.nameValuePair "UV_PYTHON" "${lib.getExe pkgs.python311}") + (lib.nameValuePair "DEVSHELL_NO_MOTD" 1) + { + name = "PYTHONPATH"; + unset = true; + } + ]; + devshell.startup.pre-commit-hook.text = config.pre-commit.installationScript; + }; + + treefmt = { + projectRootFile = "flake.nix"; + programs = { + nixfmt.enable = true; + ruff-check.enable = true; + ruff-format.enable = true; + }; + }; + + pre-commit.settings.hooks.treefmt = { + enable = true; + name = "treefmt"; + entry = lib.getExe config.treefmt.build.wrapper; + pass_filenames = false; + }; + }; + }; + + inputs = { + # flake-parts + + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + + # nixpkgs + + nixpkgs.follows = "nixpkgs-unstable"; + nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; + + # flake modules + + devshell = { + url = "github:numtide/devshell"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + git-hooks-nix = { + url = "github:cachix/git-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.nixpkgs-stable.follows = "nixpkgs"; + }; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + # libraries + + pyproject-nix = { + url = "github:nix-community/pyproject.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + uv2nix = { + url = "github:adisbladis/uv2nix"; + inputs.pyproject-nix.follows = "pyproject-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; +} diff --git a/templates/python-uv/pyproject.toml b/templates/python-uv/pyproject.toml new file mode 100644 index 0000000..25db33e --- /dev/null +++ b/templates/python-uv/pyproject.toml @@ -0,0 +1,7 @@ +[project] +name = "python-uv" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.11" +dependencies = [] diff --git a/templates/python-uv/uv.lock b/templates/python-uv/uv.lock new file mode 100644 index 0000000..ee441eb --- /dev/null +++ b/templates/python-uv/uv.lock @@ -0,0 +1,7 @@ +version = 1 +requires-python = ">=3.11" + +[[package]] +name = "python-uv" +version = "0.1.0" +source = { editable = "." }