Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix support #40

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ The main thing that differs SSVP from other status pages is that it's designed f

**Full installation guide**: https://ssvp.docs.amyip.net/installing.html

You need to initialize a database software - either mysql, postgres, or sqlite (can be done by the installer).

### NixOS (23.11/unstable or later)

Read the [NixOS section](https://ssvp.docs.amyip.net/installing.html#NixOS) of the documentation.

### Other Distributions

- Clone the repostiory:

```sh
git clone --depth=1 https://github.com/amyipdev/ssvp
```

- Set up a database service (sqlite3, mysql, mariadb, or postgres)

Run the installer:
```sh
cd ssvp
Expand Down
104 changes: 96 additions & 8 deletions docs/installing.rst
Original file line number Diff line number Diff line change
@@ -1,20 +1,69 @@
Installation
============

Installation of SSVP is usually simple, thanks to the easy installer (:code:`./install.sh`).
Installation of SSVP is usually simple, thanks to the
easy installer (:code:`./install.sh`).

Supported Operating Systems
---------------------------

Right now, we're currently focusing on just supporting Linux. \*BSD and macOS support may come in the future; Windows support is unlikely.

Theoretically, any Linux distribution should work. We currently only officially support **Debian 12** and **Fedora 38**.

Our dependency installer currently has support for most **apt**-based and **dnf/yum**-based distributions. Support for other package managers is a `planned feature <https://github.com/amyipdev/ssvp/issues/23>`_.
The dependency verifier works on all systems, **but cannot check the presence of libpq and its headers**.
Support has a few main levels:

- Level 0: **Great Support**. Every commit is thoroughly tested on these
levels, usually due to developers running this on their own machines.
Support on these should be perfect. It is not necessary for a platform
to be level 0 for SSVP to be production-ready on it; however, level 0
platforms are the least likely to have bugs.
- Level 1: **Good Support**. These are environments known to work well.
No workarounds should be required. These platforms should survive major
changes to SSVP with ease, are tested in pipelines, and will always be
tested before any `"minor" <https://semver.org/>`_ releases.
They should be perfectly fine for production.
- Level 2: **Decent Support**. These environments should work just fine.
Minimal to no workarounds should be required. It is recommended to run
a release version of SSVP on these platforms, instead of running main.
Minor releases will have changes tested; however, testing may not be
as thorough. These are still fine to use in production, but a level 1
platform is recommended.
- Level 3: **Theoretical Support**. In theory, this platform should work
fine; it might have even been tested once. However, it's unknown whether
it works for sure. These platforms may require workarounds, and are not
recommended.
- Level 4: **Unknown Support**. These platforms have completely unknown
support. They have never been tested. Workarounds will likely be required.
- Level -1: **Borked**. These platforms are known not to work. If you'd like
to help make them work, feel free to `contribute <contributing.html>`_.

..
TODO: alphabetize

.. list-table::

* - Operating System
- Support Level
- Required OS Version
- Packaging Info
* - Fedora
- 0
- unknown
-
* - Debian
- 0
- unknown
-
* - NixOS
- 1
- 23.11/unstable
-
* - Ubuntu
- 3
- unknown
-

If you have to install dependencies manually, be aware that you need all of the packages list `here <https://github.com/amyipdev/ssvp/blob/main/installer/autoinstall-deps-system.sh>`_.

If you're on **NixOS**, jump to the :ref:`NixOS instructions<NixOS>`.

Downloading SSVP
----------------

Expand Down Expand Up @@ -70,4 +119,43 @@ The "enable on boot" option for systemd will take care of everything. OpenRC is
You're now done with the installation. You can run the server by running `srv/tmux.sh`. It should print :code:`no current client` when done. You can check on the server by running `tmux attach`,
and disconnect from it by pressing `CTRL-b d`.

If you need to change settings in your configuration file, please see the `configuration guide <configuration.html>`_.
If you need to change settings in your configuration file, please see the `configuration guide <configuration.html>`_.

NixOS
-----

.. _NixOS:

This section is only necessary for those using NixOS.

Because the Nix installer can't create a configuration file of its own, you need to create one.
See `the configuration manual <configuration.html>`_ for how to do this.

First, you need to open up your configuration file (either a local one, or `/etc/nixos/configuration.nix`). Locate the :code:`let` list, and add:

.. code-block:: nix

ssvp = builtins.fetchTarball "https://github.com/amyipdev/ssvp/archive/nix-shell-distrib.tar.gz";

Then, locate the :code:`imports` list, and add:

.. code-block:: nix

"${ssvp}/service.nix"

Below the end of the imports list, then add:

.. code-block:: nix

services.ssvp = {
enable = true;
configFile = "/path/to/ssvp-config-file";
}

Save and exit the file. Then, reload your nix config:

.. code-block:: bash

nixos-reload switch

SSVP is now up and running.
1 change: 0 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/bash
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# ssvp: server statistics viewer project
Expand Down
18 changes: 9 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Flask
mysql-connector-python
ping3
requests
psycopg2
pyopenssl
gunicorn
sphinx
sphinx_rtd_theme
Flask==2.3.2
mysql-connector-python==8.1.0
ping3==4.8.4
requests==2.31.0
psycopg2==2.9.6
pyopenssl==23.2.0
gunicorn==21.2.0
sphinx==6.2.1
sphinx_rtd_theme==1.2.2
78 changes: 78 additions & 0 deletions service.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{ pkgs, config, lib, ... }:

with lib;

let
python3 = pkgs.python311.withPackages (ps: with ps; [
flask
mysql-connector
ping3
requests
psycopg2
gunicorn
]);

cfg = config.services.ssvp;
npmlock2nix = import (builtins.fetchTarball
"https://github.com/nix-community/npmlock2nix/archive/9197bbf.tar.gz"
) {};
nodeModules = npmlock2nix.v2.node_modules {
src = ./.;
installPhase = "mv node_modules $out/";
};
ins = pkgs.runCommand "ssvp" {src = ./.; buildInputs = with pkgs; [ nodejs ];} ''
cp -r --no-preserve=all $src $out
cd $out
cp -r ${nodeModules} node_modules
make
'';

in {
options.services.ssvp = {
enable = mkEnableOption "SSVP Production Environment";
configFile = mkOption {
type = types.str;
description = "Configuration file";
};
};
config = mkIf cfg.enable {
systemd.services.ssvp-gunicorn = {
path = with pkgs; [
python3
which
jq
bash
];
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
script = ''
cd ${ins}
${pkgs.bash}/bin/bash srv/gunicorn.sh
'';
environment = { SSVP_CONFIG = cfg.configFile; };
};
systemd.timers.ssvp-interval = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnUnitActiveSec = "5m";
Unit = "ssvp-interval.service";
};
};
systemd.services.ssvp-interval = {
path = with pkgs; [
python3
bash
];
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
script = ''
cd ${ins}
${python3}/bin/python3 srv/interval.py
'';
serviceConfig = {
Type = "oneshot";
};
environment = { SSVP_CONFIG = cfg.configFile; };
};
};
}
2 changes: 1 addition & 1 deletion srv/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

app = Flask(__name__, template_folder="../web")
cd = os.path.dirname(__file__)
config = json.load(open(f"{cd}/ssvp-config.json", "r"))
config = json.load(open(x if (x := os.getenv("SSVP_CONFIG")) else f"{cd}/ssvp-config.json", "r"))
db = getdb.get_handler(config["database"])


Expand Down
8 changes: 6 additions & 2 deletions srv/gunicorn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ set -e

cd "$(dirname "$0")"

SSL=$(jq -j .ssl ssvp-config.json)
PORT=$(jq -j .port ssvp-config.json)
if [ "$SSVP_CONFIG" == "" ]; then
SSVP_CONFIG=ssvp-config.json
fi

SSL=$(jq -j .ssl $SSVP_CONFIG)
PORT=$(jq -j .port $SSVP_CONFIG)

if [ $PORT == "null" ]; then
if [ $SSL != "null" ]; then
Expand Down
2 changes: 1 addition & 1 deletion srv/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import test_modules

cd = os.path.dirname(__file__)
config = json.load(open(f"{cd}/ssvp-config.json", "r"))
config = json.load(open(x if (x := os.getenv("SSVP_CONFIG")) else f"{cd}/ssvp-config.json", "r"))
db = getdb.get_handler(config["database"])


Expand Down
1 change: 0 additions & 1 deletion uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/bash
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# ssvp: server statistics viewer project
Expand Down