Compare commits

...

8 Commits

Author SHA1 Message Date
Inex Code 22ae16b8fd Update nixos version and change 301 to 302 2023-03-20 17:57:02 +02:00
inexcode 096cb76103 Update NixOS 2022-08-26 13:53:11 +04:00
Inex Code 4b7469355d Fix uris 2022-04-28 13:54:48 +03:00
Inex Code 280b468025 Изменил(а) на 'app.py' 2022-04-28 12:52:37 +03:00
Inex Code 62fe0a806e Add strip 2022-04-28 12:49:35 +03:00
Illia Chub 537f5b0be6 Added obligatory channel_url.txt 2022-02-17 21:11:50 +02:00
Illia Chub f554236262 Added obligatory channel_url.txt 2022-02-17 21:08:49 +02:00
Illia Chub ad32f7b4be Reformatted file structure for NixOS deployment 2022-02-17 20:08:18 +02:00
7 changed files with 20 additions and 32 deletions

1
.gitignore vendored
View File

@ -158,4 +158,3 @@ cython_debug/
# End of https://www.toptal.com/developers/gitignore/api/python
channel_url.txt

View File

@ -7,14 +7,14 @@ from flask import Flask, request, jsonify, redirect
from flask_restful import Api, Resource, reqparse
# Read the current nixos channel URL from file channel_url.txt
current_channel = open("channel_url.txt", "r").read()
current_channel = open("/var/channel_url.txt", "r").read().strip()
class Channel(Resource):
def get(self):
"""GET request returns the 301 redirect to the
current validated NixOS channel
"""GET request returns the 302 redirect to the
current validated NixOS channel
"""
return redirect(current_channel, code=301)
return redirect(current_channel, code=302)
def post(self):
"""POST a new channel, save it to file and update
@ -25,20 +25,22 @@ class Channel(Resource):
args = parser.parse_args()
channel = args['channel']
# Save the new channel to file
with open("channel_url.txt", "w") as f:
with open("/var/channel_url.txt", "w") as f:
f.write(channel)
# Update the current channel
global current_channel
current_channel = channel
return jsonify({"message": "Channel updated"})
class GetNewChannel(Resource):
def post(self):
r = requests.get("https://nixos.org/channels/nixos-21.05")
r = requests.get("https://nixos.org/channels/nixos-22.11")
channel = r.url
# Save the new channel to file
with open("channel_url.txt", "w") as f:
with open("/var/channel_url.txt", "w") as f:
f.write(channel)
# Update the current channel
global current_channel
current_channel = channel
return jsonify({"message": "Channel updated", "channel": channel})

1
channel_url.txt Normal file
View File

@ -0,0 +1 @@
https://nixos.org/channels/nixos-22.05

0
requirements.txt Normal file
View File

10
setup.py Normal file
View File

@ -0,0 +1,10 @@
from setuptools import setup, find_packages
setup(
name="nix-channel-redirect",
version="1.0.0",
packages=find_packages(),
scripts=[
"app.py",
],
)

View File

@ -1,24 +0,0 @@
{ pkgs ? import <nixpkgs> {} }:
let
sp-python = pkgs.python39.withPackages (p: with p; [
flask
flask-restful
setuptools
portalocker
pytest
pytest-mock
pytest-datadir
coverage
requests
]);
in
pkgs.mkShell {
buildInputs = [
sp-python
pkgs.black
];
shellHook = ''
PYTHONPATH=${sp-python}/${sp-python.sitePackages}
# maybe set more env-vars
'';
}