diff --git a/selfprivacy_api/dependencies.py b/selfprivacy_api/dependencies.py index 74252c7..3284fd8 100644 --- a/selfprivacy_api/dependencies.py +++ b/selfprivacy_api/dependencies.py @@ -27,4 +27,4 @@ async def get_token_header( def get_api_version() -> str: """Get API version""" - return "2.1.1" + return "2.1.2" diff --git a/selfprivacy_api/migrations/__init__.py b/selfprivacy_api/migrations/__init__.py index 7385548..adb7d24 100644 --- a/selfprivacy_api/migrations/__init__.py +++ b/selfprivacy_api/migrations/__init__.py @@ -19,6 +19,9 @@ from selfprivacy_api.migrations.migrate_to_selfprivacy_channel import ( ) from selfprivacy_api.migrations.mount_volume import MountVolume from selfprivacy_api.migrations.providers import CreateProviderFields +from selfprivacy_api.migrations.prepare_for_nixos_2211 import ( + MigrateToSelfprivacyChannelFrom2205, +) migrations = [ FixNixosConfigBranch(), @@ -27,6 +30,7 @@ migrations = [ MountVolume(), CheckForFailedBindsMigration(), CreateProviderFields(), + MigrateToSelfprivacyChannelFrom2205(), ] diff --git a/selfprivacy_api/migrations/prepare_for_nixos_2211.py b/selfprivacy_api/migrations/prepare_for_nixos_2211.py new file mode 100644 index 0000000..849c262 --- /dev/null +++ b/selfprivacy_api/migrations/prepare_for_nixos_2211.py @@ -0,0 +1,58 @@ +import os +import subprocess + +from selfprivacy_api.migrations.migration import Migration + + +class MigrateToSelfprivacyChannelFrom2205(Migration): + """Migrate to selfprivacy Nix channel. + For some reason NixOS 22.05 servers initialized with the nixos channel instead of selfprivacy. + This stops us from upgrading to NixOS 22.11 + """ + + def get_migration_name(self): + return "migrate_to_selfprivacy_channel_from_2205" + + def get_migration_description(self): + return "Migrate to selfprivacy Nix channel from NixOS 22.05." + + def is_migration_needed(self): + try: + output = subprocess.check_output( + ["nix-channel", "--list"], start_new_session=True + ) + output = output.decode("utf-8") + first_line = output.split("\n", maxsplit=1)[0] + return first_line.startswith("nixos") and ( + first_line.endswith("nixos-22.05") + ) + except subprocess.CalledProcessError: + return False + + def migrate(self): + # Change the channel and update them. + # Also, go to /etc/nixos directory and make a git pull + current_working_directory = os.getcwd() + try: + print("Changing channel") + os.chdir("/etc/nixos") + subprocess.check_output( + [ + "nix-channel", + "--add", + "https://channel.selfprivacy.org/nixos-selfpricacy", + "nixos", + ] + ) + subprocess.check_output(["nix-channel", "--update"]) + nixos_config_branch = subprocess.check_output( + ["git", "rev-parse", "--abbrev-ref", "HEAD"], start_new_session=True + ) + if nixos_config_branch.decode("utf-8").strip() == "api-redis": + print("Also changing nixos-config branch from api-redis to master") + subprocess.check_output(["git", "checkout", "master"]) + subprocess.check_output(["git", "pull"]) + os.chdir(current_working_directory) + except subprocess.CalledProcessError: + os.chdir(current_working_directory) + print("Error") diff --git a/setup.py b/setup.py index e0c5716..51606b6 100755 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name="selfprivacy_api", - version="2.1.1", + version="2.1.2", packages=find_packages(), scripts=[ "selfprivacy_api/app.py",