mirror of
https://github.com/Swarsel/.dotfiles.git
synced 2025-12-06 09:07:21 +01:00
feat: expose python flake to all systems
This commit is contained in:
parent
5915a28ba0
commit
fbc134388d
1 changed files with 71 additions and 58 deletions
|
|
@ -32,6 +32,7 @@
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (nixpkgs) lib;
|
inherit (nixpkgs) lib;
|
||||||
|
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
|
||||||
|
|
||||||
# Load a uv workspace from a workspace root.
|
# Load a uv workspace from a workspace root.
|
||||||
# Uv2nix treats all uv projects as workspace projects.
|
# Uv2nix treats all uv projects as workspace projects.
|
||||||
|
|
@ -55,80 +56,92 @@
|
||||||
# This is an additional overlay implementing build fixups.
|
# This is an additional overlay implementing build fixups.
|
||||||
# See:
|
# See:
|
||||||
# - https://pyproject-nix.github.io/uv2nix/FAQ.html
|
# - https://pyproject-nix.github.io/uv2nix/FAQ.html
|
||||||
pyprojectOverrides = _final: _prev: {
|
|
||||||
# Implement build fixups here.
|
|
||||||
};
|
|
||||||
|
|
||||||
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
|
||||||
python = pkgs.python312;
|
|
||||||
|
|
||||||
# Construct package set
|
# Construct package set
|
||||||
pythonSet =
|
pythonSets = forAllSystems
|
||||||
# Use base package set from pyproject.nix builders
|
(system:
|
||||||
(pkgs.callPackage pyproject-nix.build.packages {
|
let
|
||||||
inherit python;
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
}).overrideScope
|
pyprojectOverrides = _final: _prev: {
|
||||||
(
|
# Implement build fixups here.
|
||||||
lib.composeManyExtensions [
|
};
|
||||||
pyproject-build-systems.overlays.default
|
baseSet = pkgs.callPackage pyproject-nix.build.packages {
|
||||||
overlay
|
python = pkgs.python312;
|
||||||
pyprojectOverrides
|
};
|
||||||
]
|
in
|
||||||
);
|
# Use base package set from pyproject.nix builders
|
||||||
|
baseSet.overrideScope
|
||||||
|
(
|
||||||
|
lib.composeManyExtensions [
|
||||||
|
pyproject-build-systems.overlays.default
|
||||||
|
overlay
|
||||||
|
pyprojectOverrides
|
||||||
|
]
|
||||||
|
));
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Package a virtual environment as our main application.
|
# Package a virtual environment as our main application.
|
||||||
#
|
#
|
||||||
# Enable no optional dependencies for production build.
|
# Enable no optional dependencies for production build.
|
||||||
packages.x86_64-linux.default = pythonSet.mkVirtualEnv "name-env" workspace.deps.default;
|
packages = forAllSystems (system:
|
||||||
|
let
|
||||||
|
pythonSet = pythonSets.${system};
|
||||||
|
in
|
||||||
|
{ default = pythonSet.mkVirtualEnv "name-env" workspace.deps.default; });
|
||||||
|
|
||||||
# This example provides two different modes of development:
|
# This example provides two different modes of development:
|
||||||
# - Impurely using uv to manage virtual environments
|
# - Impurely using uv to manage virtual environments
|
||||||
# - Pure development using uv2nix to manage virtual environments
|
# - Pure development using uv2nix to manage virtual environments
|
||||||
devShells.x86_64-linux = {
|
devShells = forAllSystems
|
||||||
# This devShell uses uv2nix to construct a virtual environment purely from Nix, using the same dependency specification as the application.
|
(system:
|
||||||
# The notable difference is that we also apply another overlay here enabling editable mode ( https://setuptools.pypa.io/en/latest/userguide/development_mode.html ).
|
|
||||||
#
|
|
||||||
# This means that any changes done to your local files do not require a rebuild.
|
|
||||||
default =
|
|
||||||
let
|
let
|
||||||
# Create an overlay enabling editable mode for all local dependencies.
|
pythonSet = pythonSets.${system};
|
||||||
editableOverlay = workspace.mkEditablePyprojectOverlay {
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
# Use environment variable
|
|
||||||
root = "$REPO_ROOT";
|
|
||||||
# Optional: Only enable editable for these packages
|
|
||||||
# members = [ "hello-world" ];
|
|
||||||
};
|
|
||||||
|
|
||||||
# Override previous set with our overrideable overlay.
|
|
||||||
editablePythonSet = pythonSet.overrideScope editableOverlay;
|
|
||||||
|
|
||||||
# Build virtual environment, with local packages being editable.
|
|
||||||
#
|
|
||||||
# Enable all optional dependencies for development.
|
|
||||||
virtualenv = editablePythonSet.mkVirtualEnv "name-dev-env" workspace.deps.all;
|
|
||||||
|
|
||||||
in
|
in
|
||||||
pkgs.mkShell {
|
{
|
||||||
packages = [
|
# This devShell uses uv2nix to construct a virtual environment purely from Nix, using the same dependency specification as the application.
|
||||||
virtualenv
|
# The notable difference is that we also apply another overlay here enabling editable mode ( https://setuptools.pypa.io/en/latest/userguide/development_mode.html ).
|
||||||
pkgs.uv
|
#
|
||||||
];
|
# This means that any changes done to your local files do not require a rebuild.
|
||||||
shellHook = ''
|
default =
|
||||||
# Undo dependency propagation by nixpkgs.
|
let
|
||||||
unset PYTHONPATH
|
# Create an overlay enabling editable mode for all local dependencies.
|
||||||
|
editableOverlay = workspace.mkEditablePyprojectOverlay {
|
||||||
|
# Use environment variable
|
||||||
|
root = "$REPO_ROOT";
|
||||||
|
# Optional: Only enable editable for these packages
|
||||||
|
# members = [ "hello-world" ];
|
||||||
|
};
|
||||||
|
|
||||||
# Don't create venv using uv
|
# Override previous set with our overrideable overlay.
|
||||||
export UV_NO_SYNC=1
|
editablePythonSet = pythonSet.overrideScope editableOverlay;
|
||||||
|
|
||||||
# Prevent uv from downloading managed Python's
|
# Build virtual environment, with local packages being editable.
|
||||||
export UV_PYTHON_DOWNLOADS=never
|
#
|
||||||
|
# Enable all optional dependencies for development.
|
||||||
|
virtualenv = editablePythonSet.mkVirtualEnv "name-dev-env" workspace.deps.all;
|
||||||
|
|
||||||
# Get repository root using git. This is expanded at runtime by the editable `.pth` machinery.
|
in
|
||||||
export REPO_ROOT=$(git rev-parse --show-toplevel)
|
pkgs.mkShell {
|
||||||
'';
|
packages = [
|
||||||
};
|
virtualenv
|
||||||
};
|
pkgs.uv
|
||||||
|
];
|
||||||
|
shellHook = ''
|
||||||
|
# Undo dependency propagation by nixpkgs.
|
||||||
|
unset PYTHONPATH
|
||||||
|
|
||||||
|
# Don't create venv using uv
|
||||||
|
export UV_NO_SYNC=1
|
||||||
|
|
||||||
|
# Prevent uv from downloading managed Python's
|
||||||
|
export UV_PYTHON_DOWNLOADS=never
|
||||||
|
|
||||||
|
# Get repository root using git. This is expanded at runtime by the editable `.pth` machinery.
|
||||||
|
export REPO_ROOT=$(git rev-parse --show-toplevel)
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue