diff options
| -rw-r--r-- | flake.lock | 99 | ||||
| -rw-r--r-- | flake.nix | 94 |
2 files changed, 193 insertions, 0 deletions
diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..55fffc0 --- /dev/null +++ b/flake.lock @@ -0,0 +1,99 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1749285348, + "narHash": "sha256-frdhQvPbmDYaScPFiCnfdh3B/Vh81Uuoo0w5TkWmmjU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3e3afe5174c561dee0df6f2c2b2236990146329f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pyproject-build-systems": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "pyproject-nix": [ + "pyproject-nix" + ], + "uv2nix": [ + "uv2nix" + ] + }, + "locked": { + "lastModified": 1749519371, + "narHash": "sha256-UJONN7mA2stweZCoRcry2aa1XTTBL0AfUOY84Lmqhos=", + "owner": "pyproject-nix", + "repo": "build-system-pkgs", + "rev": "7c06967eca687f3482624250428cc12f43c92523", + "type": "github" + }, + "original": { + "owner": "pyproject-nix", + "repo": "build-system-pkgs", + "type": "github" + } + }, + "pyproject-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1746540146, + "narHash": "sha256-QxdHGNpbicIrw5t6U3x+ZxeY/7IEJ6lYbvsjXmcxFIM=", + "owner": "pyproject-nix", + "repo": "pyproject.nix", + "rev": "e09c10c24ebb955125fda449939bfba664c467fd", + "type": "github" + }, + "original": { + "owner": "pyproject-nix", + "repo": "pyproject.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "pyproject-build-systems": "pyproject-build-systems", + "pyproject-nix": "pyproject-nix", + "uv2nix": "uv2nix" + } + }, + "uv2nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "pyproject-nix": [ + "pyproject-nix" + ] + }, + "locked": { + "lastModified": 1749170547, + "narHash": "sha256-zOptuFhTr9P0A+unFaOBFx5E5T6yx0qE8VrUGVrM96U=", + "owner": "pyproject-nix", + "repo": "uv2nix", + "rev": "7ae60727d4fc2e41aefd30da665e4f92ba8298f1", + "type": "github" + }, + "original": { + "owner": "pyproject-nix", + "repo": "uv2nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ceb084f --- /dev/null +++ b/flake.nix @@ -0,0 +1,94 @@ +{ + description = "Focaccia: A Symbolic Tester for QEMU"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + pyproject-nix = { + url = "github:pyproject-nix/pyproject.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + uv2nix = { + url = "github:pyproject-nix/uv2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.pyproject-nix.follows = "pyproject-nix"; + }; + + pyproject-build-systems = { + url = "github:pyproject-nix/build-system-pkgs"; + inputs.uv2nix.follows = "uv2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.pyproject-nix.follows = "pyproject-nix"; + }; + }; + + outputs = { + self, + uv2nix, + nixpkgs, + pyproject-nix, + pyproject-build-systems, + ... + }: + let + # Define system arch + system = "aarch64-darwin"; + + # Refine nixpkgs used in flake to system arch + pkgs = import nixpkgs { + inherit system; + }; + + # Pin Python version + python = pkgs.python312; + + # Define workspace root and load uv workspace metadata + workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; }; + + # Create an overlay for Nix that includes extracted Python packages declared as dependencies + # in uv + overlay = workspace.mkPyprojectOverlay { sourcePreference = "wheel"; }; + + # Another overlay layer for flake-specific overloads + # This might be needed because uv does not have sufficient metadata + # Here, uv does include metadata about build systems used by each dependency + # Ergo we need to add a nativeBuildInput to miasm because it depends on setuptools for its + # installation + pyprojectOverrides = self: super: { + miasm = super.miasm.overrideAttrs (old: { + nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ self.setuptools ]; + }); + python-cpuid = super.python-cpuid.overrideAttrs (old: { + nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ + self.setuptools + pkgs.clang + ]; + }); + }; + + # Build a set of Python packages + # The call to callPackage here uses the base package set from pyproject.nix + # We inherit the Python version to ensure that the packages have the same version + # + # The overrideScope here customizes the Python package set with an overlay defined by the + # composition of three overlay functions + pythonSet = (pkgs.callPackage pyproject-nix.build.packages { inherit python; }). + overrideScope (pkgs.lib.composeManyExtensions [ + pyproject-build-systems.overlays.default + overlay + pyprojectOverrides + ]); + + # Create a Python venv with the default dependency group + pythonEnv = pythonSet.mkVirtualEnv "focaccia-env" workspace.deps.default; + in { + packages.aarch64-darwin.default = pythonEnv; + + apps.aarch64-darwin.default = { + type = "app"; + program = "${self.packages.aarch64-darwin.default}/bin/focaccia"; + }; + }; +} + |