refactor: rewrite in rust
This commit is contained in:
parent
20a3e8b437
commit
ed493cff29
72 changed files with 5684 additions and 3688 deletions
197
flake.nix
197
flake.nix
|
|
@ -4,23 +4,12 @@
|
|||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
|
||||
pyproject-nix = {
|
||||
url = "github:pyproject-nix/pyproject.nix";
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
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";
|
||||
};
|
||||
crane.url = "github:ipetkov/crane";
|
||||
|
||||
git-hooks = {
|
||||
url = "github:cachix/git-hooks.nix";
|
||||
|
|
@ -32,9 +21,8 @@
|
|||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
pyproject-nix,
|
||||
uv2nix,
|
||||
pyproject-build-systems,
|
||||
rust-overlay,
|
||||
crane,
|
||||
git-hooks,
|
||||
...
|
||||
}:
|
||||
|
|
@ -42,110 +30,87 @@
|
|||
inherit (nixpkgs) lib;
|
||||
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
|
||||
|
||||
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
|
||||
mkPkgs =
|
||||
system:
|
||||
import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ rust-overlay.overlays.default ];
|
||||
};
|
||||
|
||||
overlay = workspace.mkPyprojectOverlay {
|
||||
sourcePreference = "wheel";
|
||||
};
|
||||
|
||||
editableOverlay = workspace.mkEditablePyprojectOverlay {
|
||||
root = "$REPO_ROOT";
|
||||
};
|
||||
|
||||
pythonSets = forAllSystems (
|
||||
mkCraneLib =
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
inherit (pkgs) stdenv;
|
||||
|
||||
baseSet = pkgs.callPackage pyproject-nix.build.packages {
|
||||
python = pkgs.python313;
|
||||
pkgs = mkPkgs system;
|
||||
toolchain = pkgs.rust-bin.stable.latest.default.override {
|
||||
extensions = [
|
||||
"rust-src"
|
||||
"rust-analyzer"
|
||||
];
|
||||
};
|
||||
|
||||
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
|
||||
]
|
||||
)
|
||||
);
|
||||
(crane.mkLib pkgs).overrideToolchain toolchain;
|
||||
|
||||
mkStreamd =
|
||||
system:
|
||||
let
|
||||
craneLib = mkCraneLib system;
|
||||
|
||||
commonArgs = {
|
||||
src = craneLib.path ./.;
|
||||
pname = "streamd";
|
||||
version = "0.1.0";
|
||||
strictDeps = true;
|
||||
};
|
||||
|
||||
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
||||
in
|
||||
craneLib.buildPackage (
|
||||
commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
|
||||
passthru = {
|
||||
inherit cargoArtifacts;
|
||||
tests = {
|
||||
clippy = craneLib.cargoClippy (
|
||||
commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
cargoClippyExtraArgs = "--all-targets -- -D warnings";
|
||||
}
|
||||
);
|
||||
fmt = craneLib.cargoFmt { src = commonArgs.src; };
|
||||
test = craneLib.cargoTest (commonArgs // { inherit cargoArtifacts; });
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
mkGitHooksCheck =
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
pythonSet = pythonSets.${system};
|
||||
venv = pythonSet.mkVirtualEnv "streamd-check-env" workspace.deps.all;
|
||||
pkgs = mkPkgs system;
|
||||
toolchain = pkgs.rust-bin.stable.latest.default;
|
||||
in
|
||||
git-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
basedpyright = {
|
||||
rustfmt = {
|
||||
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" ];
|
||||
package = toolchain;
|
||||
};
|
||||
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;
|
||||
streamd = mkStreamd system;
|
||||
in
|
||||
rec {
|
||||
streamd = mkApplication {
|
||||
venv = pythonSet.mkVirtualEnv "streamd-env" workspace.deps.default;
|
||||
package = pythonSet.streamd;
|
||||
};
|
||||
{
|
||||
inherit streamd;
|
||||
default = streamd;
|
||||
}
|
||||
);
|
||||
|
|
@ -171,8 +136,8 @@
|
|||
|
||||
package = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
default = self.packages.${pkgs.system}.streamd;
|
||||
defaultText = lib.literalExpression "inputs.streamd.packages.\${pkgs.system}.streamd";
|
||||
default = self.packages.${pkgs.stdenv.hostPlatform.system}.streamd;
|
||||
defaultText = lib.literalExpression "inputs.streamd.packages.\${pkgs.stdenv.hostPlatform.system}.streamd";
|
||||
description = "The package to use for the streamd binary.";
|
||||
};
|
||||
};
|
||||
|
|
@ -191,16 +156,24 @@
|
|||
};
|
||||
|
||||
home.shellAliases.s = "streamd";
|
||||
|
||||
programs.bash.initExtra = ''
|
||||
eval "$(${cfg.package}/bin/streamd completions bash)"
|
||||
'';
|
||||
|
||||
programs.zsh.initExtra = ''
|
||||
eval "$(${cfg.package}/bin/streamd completions zsh)"
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
checks = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pythonSet = pythonSets.${system};
|
||||
streamd = mkStreamd system;
|
||||
in
|
||||
{
|
||||
inherit (pythonSet.streamd.passthru.tests) pytest;
|
||||
inherit (streamd.passthru.tests) clippy fmt test;
|
||||
pre-commit = mkGitHooksCheck system;
|
||||
}
|
||||
);
|
||||
|
|
@ -208,24 +181,22 @@
|
|||
devShells = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
pythonSet = pythonSets.${system}.overrideScope editableOverlay;
|
||||
virtualenv = pythonSet.mkVirtualEnv "streamd-dev-env" workspace.deps.all;
|
||||
pkgs = mkPkgs system;
|
||||
toolchain = pkgs.rust-bin.stable.latest.default.override {
|
||||
extensions = [
|
||||
"rust-src"
|
||||
"rust-analyzer"
|
||||
];
|
||||
};
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
packages = [
|
||||
virtualenv
|
||||
pkgs.uv
|
||||
toolchain
|
||||
pkgs.commitizen
|
||||
];
|
||||
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}
|
||||
'';
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue