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

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:

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:

  1. Go to the AWS website.
  2. Click on the "Create an AWS Account" button and follow the steps to create an account.
  3. Once your account is created, log in and go to the "Identity and Access Management (IAM)" console.
  4. Click on "Create new users" and create a new user.
  5. Click on the "Permissions" tab and attach an "AmazonS3FullAccess" policy to the user.
  6. 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.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!