diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..8f49e8e --- /dev/null +++ b/flake.lock @@ -0,0 +1,142 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "poetry2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1729742964, + "narHash": "sha256-B4mzTcQ0FZHdpeWcpDYPERtyjJd/NIuaQ9+BV1h+MpA=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "e04df33f62cdcf93d73e9a04142464753a16db67", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1767313136, + "narHash": "sha256-16KkgfdYqjaeRGBaYsNrhPRRENs0qzkQVUooNHtoy2w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ac62194c3917d5f474c1a844b6fd6da2db95077d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-25.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "poetry2nix": { + "inputs": { + "flake-utils": "flake-utils", + "nix-github-actions": "nix-github-actions", + "nixpkgs": [ + "nixpkgs" + ], + "systems": "systems_2", + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1743690424, + "narHash": "sha256-cX98bUuKuihOaRp8dNV1Mq7u6/CQZWTPth2IJPATBXc=", + "owner": "nix-community", + "repo": "poetry2nix", + "rev": "ce2369db77f45688172384bbeb962bc6c2ea6f94", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "poetry2nix", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "poetry2nix": "poetry2nix" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "poetry2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1730120726, + "narHash": "sha256-LqHYIxMrl/1p3/kvm2ir925tZ8DkI0KA10djk8wecSk=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "9ef337e492a5555d8e17a51c911ff1f02635be15", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e8d7c49 --- /dev/null +++ b/flake.nix @@ -0,0 +1,64 @@ +{ + description = "Reproducible checks for the Object Storage Python client"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; + poetry2nix.url = "github:nix-community/poetry2nix"; + poetry2nix.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { nixpkgs, poetry2nix, ... }: + let + pkgs = import nixpkgs { system = "x86_64-linux"; }; + inherit (pkgs) lib; + dependencies = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ ./pyproject.toml ./poetry.lock ]; + }; + poetry = poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }; + python = poetry.mkPoetryEnv { + projectDir = dependencies; + python = pkgs.python310; + preferWheels = true; + groups = [ "main" ]; + checkGroups = [ ]; + extraPackages = ps: [ ps.ruff ps.pytest ps.pytest-cov ]; + overrides = poetry.defaultPoetryOverrides.extend (_final: prev: { + fetchFromPypi = args: (prev.fetchFromPypi args).overrideAttrs (old: + let + parts = lib.splitString "-" args.file; + pythonTag = builtins.elemAt parts (builtins.length parts - 3); + in + { + # PyPI's wheel redirect uses the Python tag, not a literal "wheel". + predictedURL = builtins.replaceStrings + [ "/wheel/" ] [ "/${pythonTag}/" ] old.predictedURL; + }); + }); + }; + source = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ ./src ./tests ./pyproject.toml ]; + }; + in + { + checks.x86_64-linux = { + lint = pkgs.runCommand "object-storage-lint" { nativeBuildInputs = [ python ]; } '' + cp -r ${source} source + chmod -R u+w source + cd source + ruff check src tests + touch "$out" + ''; + unit = pkgs.runCommand "object-storage-unit" { nativeBuildInputs = [ python ]; } '' + cp -r ${source} source + chmod -R u+w source + cd source + export PYTHONPATH="$PWD/src" + pytest --cov-report term-missing --cov=./src ./tests/unit + mkdir -p "$out" + cp .coverage "$out/" + ''; + }; + }; +}