Go to file
2024-03-19 02:58:23 +04:00
.idea chore: Project files for IDEA 2023-02-06 11:50:16 +03:00
.vscode Migrate to FastAPI (#13) 2022-08-25 20:03:56 +03:00
nixos refactor: Move from nix-shell to nix flake 2024-01-10 15:05:10 +02:00
selfprivacy_api fix: Mark md5 as not used for security 2024-03-15 16:14:31 +04:00
tests fix: future mock are now more in the future 2024-03-15 16:14:31 +04:00
.coveragerc More unit tests and bugfixes (#7) 2022-01-10 22:35:00 +02:00
.drone.yml fix ci: pass coverage.xml to sonar-scanner 2024-03-19 02:58:23 +04:00
.flake8 style: set 88 as a line length limit 2023-07-19 16:49:35 +03:00
.gitignore flake: NixOS VM Test for running pytest with Redis; nix flake check 2024-02-01 00:05:16 +04:00
.pylintrc style: set 88 as a line length limit 2023-07-19 16:49:35 +03:00
CONTRIBUTING.md docs: add CONTRIBUTING.md 2022-12-30 21:21:34 +03:00
default.nix flake: NixOS VM Test for running pytest with Redis; nix flake check 2024-02-01 00:05:16 +04:00
flake.lock chore(api): update nixpkgs version and add a script to do it 2024-03-15 11:01:34 +00:00
flake.nix fix ci: pass coverage.xml to sonar-scanner 2024-03-19 02:58:23 +04:00
LICENSE Add a license 2021-11-18 10:05:04 +02:00
nix-dependencies-diagram.puml refactor: Move from nix-shell to nix flake 2024-01-10 15:05:10 +02:00
pyproject.toml Migrate to FastAPI (#13) 2022-08-25 20:03:56 +03:00
README.md flake: NixOS VM Test for running pytest with Redis; nix flake check 2024-02-01 00:05:16 +04:00
setup.py chore: Bump version to 3.1.0 2024-03-07 23:12:45 +03:00
sync-nixpkgs.sh chore(api): update nixpkgs version and add a script to do it 2024-03-15 11:01:34 +00:00

SelfPrivacy GraphQL API which allows app to control your server

build

$ nix build

In case of successful build, you should get the ./result symlink to a folder (in /nix/store) with build contents.

develop

$ nix develop
[SP devshell:/dir/selfprivacy-rest-api]$ python
Python 3.10.13 (main, Aug 24 2023, 12:59:26) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(ins)>>>

If you don't have experimental flakes enabled, you can use the following command:

nix --extra-experimental-features nix-command --extra-experimental-features flakes develop

testing

Run the test suite by running coverage with pytest inside an ephemeral NixOS VM with redis service enabled:

$ nix flake check -L

Run the same test suite, but additionally create ./result/coverage.xml in the current directory:

$ nix build .#checks.x86_64-linux.default -L

Alternatively, just print the path to /nix/store/...coverage.xml without creating any files in the current directory:

$ nix build .#checks.x86_64-linux.default -L --print-out-paths --no-link

Run the same test suite with arbitrary pytest options:

$ pytest-vm.sh # specify pytest options here, e.g. `--last-failed`

When running using the script, pytest cache is preserved between runs in .pytest_cache folder. NixOS VM state temporary resides in ${TMPDIR:=/tmp}/nixos-vm-tmp-dir/vm-state-machine during the test. Git workdir directory is shared read-write with VM via .nixos-vm-tmp-dir/shared-xchg symlink. VM accesses workdir contents via /tmp/shared mount point and /root/source symlink.

Launch VM and execute commands manually either in Linux console (user root) or using python NixOS tests driver API (refer to NixOS documentation):

$ nix run .#checks.x86_64-linux.default.driverInteractive

You can add --keep-vm-state in order to keep VM state between runs:

$ TMPDIR=".nixos-vm-tmp-dir" nix run .#checks.x86_64-linux.default.driverInteractive --keep-vm-state

Option -L/--print-build-logs is optional for all nix commands. It tells nix to print each log line one after another instead of overwriting a single one.

dependencies and dependant modules

This flake depends on a single Nix flake input - nixpkgs repository. nixpkgs repository is used for all software packages used to build, run API service, tests, etc.

In order to synchronize nixpkgs input with the same from selfprivacy-nixos-config repository, use this command:

$ nix flake lock --override-input nixpkgs nixpkgs --inputs-from git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=BRANCH

Replace BRANCH with the branch name of selfprivacy-nixos-config repository you want to sync with. During development nixpkgs input update might be required in both selfprivacy-rest-api and selfprivacy-nixos-config repositories simultaneously. So, a new feature branch might be temporarily used until selfprivacy-nixos-config gets the feature branch merged.

Show current flake inputs (e.g. nixpkgs):

$ nix flake metadata

Show selfprivacy-nixos-config Nix flake inputs (including nixpkgs):

$ nix flake metadata git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=BRANCH

Nix code for NixOS service module for API is located in NixOS configuration repository.

troubleshooting

Sometimes commands inside nix develop refuse to work properly if the calling shell lacks LANG environment variable. Try to set it before entering nix develop.