From 7db658b673f5bf9fb8fe6e48c466f24ac4bc2acb Mon Sep 17 00:00:00 2001 From: Patrick Steele Date: Mon, 2 Mar 2026 20:39:21 -0500 Subject: [PATCH] feat: a Nix build environment This commit creates a flake.nix file defining a minimal build environment for Nix users. If you have Nix, you can run nix develop to enter a FHS-compliant environment with Python 3.10, 3.11, 3.12, 3.13, and 3.14 installed, along with development tools like tox and pre-commit. From here, ordinary commands like tox -e linting,py310,py311,py312,py313,py314 work as expected. Note that this environment does not provide any Python packages except tox; all dependencies are installed via tox as if we were not using Nix. --- changelog/14520.contrib.rst | 1 + flake.lock | 59 +++++++++++++++++++++++++++++++ flake.nix | 70 +++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 changelog/14520.contrib.rst create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/changelog/14520.contrib.rst b/changelog/14520.contrib.rst new file mode 100644 index 00000000000..72214c36ba5 --- /dev/null +++ b/changelog/14520.contrib.rst @@ -0,0 +1 @@ +Flake-based Nix build environments are now supported via ``nix develop``. diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000000..256d19cb1d3 --- /dev/null +++ b/flake.lock @@ -0,0 +1,59 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1772047000, + "narHash": "sha256-7DaQVv4R97cii/Qdfy4tmDZMB2xxtyIvNGSwXBBhSmo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1267bb4920d0fc06ea916734c11b0bf004bbe17e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-25.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1772501647, + "narHash": "sha256-SwHOuy/sMYZWLrekijAkq9mHVIZXCW1Hvkeh7Z9F65Q=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "043c57fef481a2407f557d12344daf00a27d081e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "nixpkgs-unstable": "nixpkgs-unstable", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000000..3a3fdf1857b --- /dev/null +++ b/flake.nix @@ -0,0 +1,70 @@ +{ + description = "Development environment for Pytest"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11"; + nixpkgs-unstable.url = "github:NixOS/nixpkgs"; + systems.url = "github:nix-systems/default"; + }; + + outputs = { self, nixpkgs, nixpkgs-unstable, systems }: + let + forAllSystems = nixpkgs.lib.genAttrs (import systems); + mkPkgs = system: import nixpkgs { + inherit system; + overlays = [ self.overlays.newer-pre-commit ]; + }; + in + { + packages = forAllSystems (system: + let + pkgs = mkPkgs system; + in + { + fhs-test-env = pkgs.buildFHSEnv { + name = "fhs-test-env"; + targetPkgs = fhspkgs: + let + python313-with-tox = pkgs.python313.withPackages (ps: with ps; [ + tox + ]); + in + [ + python313-with-tox + + # other Pythons + fhspkgs.python310 + fhspkgs.python311 + fhspkgs.python312 + fhspkgs.python314 + + fhspkgs.bashInteractive + fhspkgs.pre-commit + + ]; + runScript = "bash"; + }; + }); + + devShells = forAllSystems (system: + let + pkgs = mkPkgs system; + in + { + default = pkgs.mkShell { + packages = [ self.packages.${system}.fhs-test-env ]; + shellHook = "exec fhs-test-env"; + }; + }); + + overlays = { + newer-pre-commit = final: prev: { + pre-commit = + let + pkgs = import nixpkgs-unstable { inherit (final.stdenv.hostPlatform) system; }; + in + pkgs.pre-commit; + }; + }; + }; +}