How to Install Picsur on NixOS Latest
Picsur is an image sharing platform developed on top of the Flask microframework. It uses SQLAlchemy for database operations and Amazon S3 for storing images. Follow this tutorial to install Picsur on NixOS Latest.
Prerequisites
- NixOS Latest installed on your system.
- A text editor to modify configuration files.
Step 1: Clone the Picsur Repository
Clone the Picsur repository from Github using the following command:
$ git clone https://github.com/rubikscraft/Picsur.git
Step 2: Install Dependencies
Picsur depends on the following packages:
- Python 3.6 or later
- Flask 1.1.2 or later
- Flask-CORS 3.0.0 or later
- Flask-Migrate 2.7.0 or later
- Flask-RESTful 0.3.8 or later
- Flask-Script 2.0.6 or later
- SQLAlchemy 1.4.22 or later
- psycopg2 2.9.1 or later
- awscli 1.18.153 or later
To install these dependencies, add the following lines to your /etc/nixos/configuration.nix file:
{ pkgs, ... }:
{
environment.systemPackages = with pkgs; [
python36 python36Packages.flask python36Packages.flask_cors python36Packages.flask_migrate python36Packages.flask_restful python36Packages.flask_script python36Packages.sqlalchemy python36Packages.psycopg2 python36Packages.awscli
];
}
Save and close the file, and then update the system packages using the following command:
$ sudo nixos-rebuild switch
Step 3: Configure PostgreSQL
Picsur uses PostgreSQL as the database backend. To install and configure PostgreSQL, add the following lines to your /etc/nixos/configuration.nix file:
{ config, pkgs, ... }:
{
services.postgresql = {
enable = true;
initialScript = builtins.readFile "${./db.sql}";
ensureDatabases = ["picsur"];
ensureUsers = [
{
name = "picsur";
ensureGroups = ["picsur"];
password = "picsur";
}
];
};
users.extraGroups = ["picsur"];
users.mutableUsers = false;
security.sudo.wheelNeedsPassword = false;
security.sudo.wheelAllUsers = true;
}
Create a file named db.sql in the same directory as /etc/nixos/configuration.nix, and copy the following lines into it:
CREATE DATABASE picsur;
GRANT ALL PRIVILEGES ON DATABASE picsur TO picsur;
This file will create the picsur database and grant all privileges to the picsur user.
Next, run the following command to update the system configuration:
$ sudo nixos-rebuild switch
Step 4: Configure Amazon S3
Picsur uses Amazon S3 to store images. To configure Amazon S3, you need to create an AWS account and create an access key and secret key. To create an access key and secret key, follow these steps:
- Go to the AWS website.
- Click on the "Create an AWS Account" button and follow the steps to create an account.
- Once your account is created, log in and go to the "Identity and Access Management (IAM)" console.
- Click on "Create new users" and create a new user.
- Click on the "Permissions" tab and attach an "AmazonS3FullAccess" policy to the user.
- Click on the "Security Credentials" tab and create an access key and secret key.
Once you have an access key and secret key, add the following lines to your /etc/nixos/configuration.nix file:
{
pkgs, ... }:
{
environment.systemPackages = with pkgs; [
# ...
];
services.picsur = {
enable = true;
accessKeyId = "YOUR_ACCESS_KEY_ID";
secretAccessKey = "YOUR_SECRET_ACCESS_KEY";
bucketName = "YOUR_BUCKET_NAME";
regionName = "YOUR_REGION_NAME";
};
}
Replace YOUR_ACCESS_KEY_ID, YOUR_SECRET_ACCESS_KEY, YOUR_BUCKET_NAME, and YOUR_REGION_NAME with your own values.
Step 5: Start the Picsur Service
To start the Picsur service, run the following command:
$ sudo systemctl start picsur.service
To enable Picsur to start automatically on boot, run the following command:
$ sudo systemctl enable picsur.service
Conclusion
You have successfully installed Picsur on NixOS Latest. You can access the Picsur web interface by visiting http://localhost:5000 in your web browser.