I’ve come up with the following flake.nix for building/developing my keepmenu project but I can’t get it to work with hatch-vcs
to set the current git version.
{
description = "Dmenu/Rofi/Wofi frontend for Keepass databases";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
};
outputs = {
self,
nixpkgs,
}: let
systems = ["x86_64-linux" "i686-linux" "aarch64-linux"];
forAllSystems = f:
nixpkgs.lib.genAttrs systems (system:
f rec {
pkgs = nixpkgs.legacyPackages.${system};
commonPackages = builtins.attrValues {
inherit
(pkgs.python3Packages)
python
pykeepass
pynput
;
};
});
in {
devShells = forAllSystems ({
pkgs,
commonPackages,
}: {
default = pkgs.mkShell {
packages = commonPackages;
};
});
packages = forAllSystems ({
pkgs,
commonPackages,
}: {
default = pkgs.python3Packages.buildPythonApplication {
name = "keepmenu";
pname = "keepmenu";
format = "pyproject";
src = ./.;
nativeBuildInputs = builtins.attrValues {
inherit
(pkgs.python3Packages)
hatchling
hatch-vcs
;
};
propagatedBuildInputs = commonPackages;
meta = {
description = "Dmenu/Rofi/Wofi frontend for Keepass databases";
homepage = "https://github.com/firecat53/keepmenu";
license = pkgs.lib.licenses.gpl3;
maintainers = ["firecat53"];
platforms = systems;
};
};
});
};
}
If I specify pulling the source from pypi or github with the version and hash it seems to work fine. Otherwise, I get the following errors when running nix build
:
Sourcing python-remove-tests-dir-hook
Sourcing python-catch-conflicts-hook.sh
Sourcing python-remove-bin-bytecode-hook.sh
Sourcing pip-build-hook
Using pipBuildPhase
Using pipShellHook
Sourcing pip-install-hook
Using pipInstallPhase
Sourcing python-imports-check-hook.sh
Using pythonImportsCheckPhase
Sourcing python-namespaces-hook
Sourcing python-catch-conflicts-hook.sh
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/70kwddhg6dsyhwsaa42z107137qr06h0-mbig43nslrlq32a51wxxnvwmd4kjb43a-source
source root is mbig43nslrlq32a51wxxnvwmd4kjb43a-source
setting SOURCE_DATE_EPOCH to timestamp 315619200 of file mbig43nslrlq32a51wxxnvwmd4kjb43a-source/tests/tests.py
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
no configure script, doing nothing
@nix { "action": "setPhase", "phase": "buildPhase" }
building
Executing pipBuildPhase
Creating a wheel...
WARNING: The directory '/homeless-shelter/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.
Processing /build/mbig43nslrlq32a51wxxnvwmd4kjb43a-source
Running command Preparing metadata (pyproject.toml)
Traceback (most recent call last):
File "/nix/store/66qrgkmha6dmcac29nvxbjsbrh77jlin-python3.10-pip-23.0.1/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
main()
File "/nix/store/66qrgkmha6dmcac29nvxbjsbrh77jlin-python3.10-pip-23.0.1/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/nix/store/66qrgkmha6dmcac29nvxbjsbrh77jlin-python3.10-pip-23.0.1/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 152, in prepare_metadata_for_build_wheel
whl_basename = backend.build_wheel(metadata_directory, config_settings)
File "/nix/store/x1nnn2lapxqkk6c7m5f0n863wx03l6b2-python3.10-hatchling-1.13.0/lib/python3.10/site-packages/hatchling/build.py", line 56, in build_wheel
return os.path.basename(next(builder.build(wheel_directory, ['standard'])))
File "/nix/store/x1nnn2lapxqkk6c7m5f0n863wx03l6b2-python3.10-hatchling-1.13.0/lib/python3.10/site-packages/hatchling/builders/plugin/interface.py", line 93, in build
self.metadata.validate_fields()
File "/nix/store/x1nnn2lapxqkk6c7m5f0n863wx03l6b2-python3.10-hatchling-1.13.0/lib/python3.10/site-packages/hatchling/metadata/core.py", line 243, in validate_fields
_ = self.version
File "/nix/store/x1nnn2lapxqkk6c7m5f0n863wx03l6b2-python3.10-hatchling-1.13.0/lib/python3.10/site-packages/hatchling/metadata/core.py", line 128, in version
self._version = self._get_version()
File "/nix/store/x1nnn2lapxqkk6c7m5f0n863wx03l6b2-python3.10-hatchling-1.13.0/lib/python3.10/site-packages/hatchling/metadata/core.py", line 226, in _get_version
version = self.hatch.version.cached
File "/nix/store/x1nnn2lapxqkk6c7m5f0n863wx03l6b2-python3.10-hatchling-1.13.0/lib/python3.10/site-packages/hatchling/metadata/core.py", line 1412, in cached
raise type(e)(message) from None
LookupError: Error getting the version from source `vcs`: setuptools-scm was unable to detect version for /build/mbig43nslrlq32a51wxxnvwmd4kjb43a-source.
Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources (such as GitHub's tarballs, a git checkout without the .git folder) don't contain the necessary metadata and will not work.
For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+https://github.com/user/proj.git#egg=proj
error: subprocess-exited-with-error
× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
full command: /nix/store/1r6n7v2wam7gkr18gxccpg7p5ywgw551-python3-3.10.12/bin/python3.10 /nix/store/66qrgkmha6dmcac29nvxbjsbrh77jlin-python3.10-pip-23.0.1/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py prepare_metadata_for_build_wheel /build/tmpu79c1gzw
cwd: /build/mbig43nslrlq32a51wxxnvwmd4kjb43a-source
Preparing metadata (pyproject.toml) ... e[?25le[?25herror
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
Is there any way to get this working without either having to keep the flake up-to-date with the current version or having to switch to using poetry? Also, I’m open to any other feedback on the flake itself, as I’m still new to Nix.
Thanks!