Skip to content

Commit 3fb8068

Browse files
Merge pull request #1872 from VWS-Python/add-nix-support
Add Nix flake support
2 parents c446c56 + 251b42e commit 3fb8068

9 files changed

Lines changed: 312 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,16 @@ jobs:
7373
echo "Error: No files were modified when updating changelog"
7474
exit 1
7575
fi
76+
77+
- name: Update VERSION file for Nix flake
78+
run: |
79+
echo "${{ steps.calver.outputs.release }}" > VERSION
80+
7681
- uses: stefanzweifel/git-auto-commit-action@v7
7782
id: commit
7883
with:
79-
commit_message: Bump CHANGELOG
80-
file_pattern: CHANGELOG.rst
84+
commit_message: Bump CHANGELOG and VERSION
85+
file_pattern: CHANGELOG.rst VERSION
8186
# Error if there are no changes.
8287
skip_dirty_check: true
8388

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,6 @@ src/*/_setuptools_scm_version.py
109109
# Ignore Mac DS_Store files
110110
.DS_Store
111111
**/.DS_Store
112+
113+
# Nix
114+
result

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ci:
1616
- linkcheck
1717
- mypy
1818
- mypy-docs
19+
- nixfmt
1920
- pylint
2021
- pyproject-fmt-fix
2122
- pyright
@@ -47,6 +48,11 @@ ci:
4748
default_install_hook_types: [pre-commit, pre-push]
4849

4950
repos:
51+
- repo: https://github.com/NixOS/nixfmt
52+
rev: v1.2.0
53+
hooks:
54+
- id: nixfmt
55+
stages: [manual]
5056
- repo: meta
5157
hooks:
5258
- id: check-useless-excludes

README.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ Requires `Homebrew`_.
3434
3535
.. _Homebrew: https://docs.brew.sh/Installation
3636

37+
With Nix
38+
^^^^^^^^
39+
40+
Requires `Nix`_.
41+
42+
.. code-block:: console
43+
44+
$ nix --extra-experimental-features 'nix-command flakes' run "github:VWS-Python/vws-cli" -- --help
45+
46+
To avoid passing ``--extra-experimental-features`` every time, `enable flakes`_ permanently.
47+
48+
.. _Nix: https://nixos.org/download/
49+
.. _enable flakes: https://wiki.nixos.org/wiki/Flakes#Enabling_flakes_permanently
50+
51+
Or add to your flake inputs:
52+
53+
.. code-block:: nix
54+
55+
{
56+
inputs.vws-cli.url = "github:VWS-Python/vws-cli";
57+
}
58+
3759
Pre-built Linux binaries
3860
^^^^^^^^^^^^^^^^^^^^^^^^
3961

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2025.03.10

docs/source/install.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ Requires `Homebrew`_.
2222
2323
.. _Homebrew: https://docs.brew.sh/Installation
2424

25+
With Nix
26+
~~~~~~~~
27+
28+
Requires Nix_.
29+
30+
.. code-block:: console
31+
:substitutions:
32+
33+
$ nix --extra-experimental-features 'nix-command flakes' develop "github:|github-owner|/|github-repository|"
34+
35+
To avoid passing ``--extra-experimental-features`` every time, `enable flakes`_ permanently.
36+
37+
.. _Nix: https://nixos.org/download/
38+
.. _enable flakes: https://wiki.nixos.org/wiki/Flakes#Enabling_flakes_permanently
39+
40+
Or add to your flake inputs:
41+
42+
.. code-block:: nix
43+
:substitutions:
44+
45+
{
46+
inputs.vws-cli.url = "github:|github-owner|/|github-repository|";
47+
}
48+
2549
Pre-built Linux (x86) binaries
2650
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2751

flake.lock

Lines changed: 99 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{
2+
description = "A CLI for the Vuforia Web Services (VWS) API";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
7+
pyproject-nix = {
8+
url = "github:pyproject-nix/pyproject.nix";
9+
inputs.nixpkgs.follows = "nixpkgs";
10+
};
11+
12+
uv2nix = {
13+
url = "github:pyproject-nix/uv2nix";
14+
inputs.pyproject-nix.follows = "pyproject-nix";
15+
inputs.nixpkgs.follows = "nixpkgs";
16+
};
17+
18+
pyproject-build-systems = {
19+
url = "github:pyproject-nix/build-system-pkgs";
20+
inputs.pyproject-nix.follows = "pyproject-nix";
21+
inputs.uv2nix.follows = "uv2nix";
22+
inputs.nixpkgs.follows = "nixpkgs";
23+
};
24+
};
25+
26+
outputs =
27+
{
28+
self,
29+
nixpkgs,
30+
pyproject-nix,
31+
uv2nix,
32+
pyproject-build-systems,
33+
...
34+
}:
35+
let
36+
inherit (nixpkgs) lib;
37+
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
38+
39+
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
40+
41+
overlay = workspace.mkPyprojectOverlay {
42+
sourcePreference = "wheel";
43+
};
44+
45+
# Read version from VERSION file, fall back to commit hash for dev builds
46+
version =
47+
let
48+
versionFile = ./VERSION;
49+
in
50+
if builtins.pathExists versionFile then
51+
lib.strings.trim (builtins.readFile versionFile)
52+
else
53+
"0.0.0+${self.shortRev or self.dirtyShortRev or "unknown"}";
54+
55+
# Override vws-cli to set the version
56+
vwsCliOverlay = final: prev: {
57+
vws-cli = prev.vws-cli.overrideAttrs (old: {
58+
env = (old.env or { }) // {
59+
SETUPTOOLS_SCM_PRETEND_VERSION = version;
60+
};
61+
});
62+
};
63+
64+
pythonSets = forAllSystems (
65+
system:
66+
let
67+
pkgs = nixpkgs.legacyPackages.${system};
68+
python = pkgs.python313;
69+
in
70+
(pkgs.callPackage pyproject-nix.build.packages {
71+
inherit python;
72+
}).overrideScope
73+
(
74+
lib.composeManyExtensions [
75+
pyproject-build-systems.overlays.wheel
76+
overlay
77+
vwsCliOverlay
78+
]
79+
)
80+
);
81+
82+
in
83+
{
84+
packages = forAllSystems (
85+
system:
86+
let
87+
pythonSet = pythonSets.${system};
88+
virtualenv = pythonSet.mkVirtualEnv "vws-cli-env" workspace.deps.default;
89+
in
90+
{
91+
default = virtualenv;
92+
vws-cli = virtualenv;
93+
}
94+
);
95+
96+
apps = forAllSystems (system: {
97+
default = {
98+
type = "app";
99+
program = "${self.packages.${system}.default}/bin/vws";
100+
};
101+
vws = {
102+
type = "app";
103+
program = "${self.packages.${system}.default}/bin/vws";
104+
};
105+
vuforia-cloud-reco = {
106+
type = "app";
107+
program = "${self.packages.${system}.default}/bin/vuforia-cloud-reco";
108+
};
109+
});
110+
111+
devShells = forAllSystems (
112+
system:
113+
let
114+
pkgs = nixpkgs.legacyPackages.${system};
115+
pythonSet = pythonSets.${system};
116+
virtualenv = pythonSet.mkVirtualEnv "vws-cli-dev-env" workspace.deps.all;
117+
in
118+
{
119+
default = pkgs.mkShell {
120+
packages = [
121+
virtualenv
122+
pkgs.uv
123+
];
124+
env = {
125+
UV_NO_SYNC = "1";
126+
UV_PYTHON = pythonSet.python.interpreter;
127+
UV_PYTHON_DOWNLOADS = "never";
128+
};
129+
shellHook = ''
130+
unset PYTHONPATH
131+
'';
132+
};
133+
}
134+
);
135+
136+
checks = forAllSystems (
137+
system:
138+
let
139+
pkgs = nixpkgs.legacyPackages.${system};
140+
in
141+
{
142+
vws-cli-smoke = pkgs.runCommand "vws-cli-smoke-test" { } ''
143+
${self.packages.${system}.default}/bin/vws --help > $out
144+
'';
145+
}
146+
);
147+
};
148+
}

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ ignore = [
290290
"bin/*",
291291
"src/*/_setuptools_scm_version.py",
292292
"zizmor.yml",
293+
"flake.lock",
294+
"flake.nix",
293295
]
294296

295297
[tool.deptry]

0 commit comments

Comments
 (0)