forked from Lassulus/refugeerouter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.nix
More file actions
78 lines (76 loc) · 2.44 KB
/
shell.nix
File metadata and controls
78 lines (76 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{ pkgs ? import <nixpkgs> {} }:
let
mach-nix = import (builtins.fetchGit {
url = "https://github.com/DavHau/mach-nix";
ref = "refs/tags/3.4.0";
}) {
pkgs = pkgs;
# python = "python39";
};
python = mach-nix.mkPython {
requirements = builtins.readFile ./requirements.txt;
};
in
pkgs.mkShell {
buildInputs = [
python
(pkgs.writers.writeDashBin "deploy" ''
rsync -va \
-e "ssh -p 45621 -o StrictHostKeyChecking=no" \
--filter=':- .gitignore' \
${toString ./.}/ ref.ptkk.de@ref.ptkk.de:/var/lib/ref.ptkk.de/code/
'')
(pkgs.writers.writeDashBin "serve" ''
cd ${toString ./.}
if test -n $PRODUCTION; then
python manage.py collectstatic
fi
python manage.py migrate
gunicorn wsgi:application -b localhost:''${PORT:-1337}
'')
(pkgs.writers.writeBashBin "init-project" ''
# https://gist.github.com/kalafut/42bd31b2fdbf7a225da94e320d3e29ba
# Simple creation of a single-app django project, as described in: https://zindilis.com/posts/django-anatomy-for-single-app/
#
# ./django_init foo
#
# This will result is the following flat structure:
#
# .
# └── foo
# ├── manage.py
# ├── settings.py
# ├── urls.py
# ├── foo
# │ ├── __init__.py
# │ ├── admin.py
# │ ├── apps.py
# │ ├── migrations
# │ │ └── __init__.py
# │ ├── models.py
# │ ├── tests.py
# │ └── views.py
# └── wsgi.py
#
# Note: this script assumes a GNU-compatible sed is installed. On macOS you can get this easily with Homebrew.
set -x
prj=$1
django-admin startproject $prj
pushd .
cd $prj
mv $prj/* .
rm __init__.py
rm -rf $prj
sed -i 's/'"''${prj}"'\.settings/settings/g' manage.py wsgi.py
sed -i 's/'"''${prj}"'\.urls/urls/g' settings.py
sed -i 's/'"''${prj}"'\.wsgi\.application/wsgi.application/g' settings.py
sed -i '/BASE_DIR = /s/Path(__file__).resolve().parent.parent/Path(__file__).resolve().parent/' settings.py
sed -i 's/'"''${prj}"'\.wsgi\.application/wsgi.application/g' settings.py
python ./manage.py startapp ''${prj}
popd
mv $prj tmp_$prj
mv tmp_$prj/* .
rmdir tmp_$prj
'')
];
}