How to Install Gitblit on NixOS Latest

Gitblit is a free, open-source Git server application that runs in a Java environment. It is a simple, lightweight, and standalone web server that provides a user-friendly interface for managing and organizing Git repositories. In this tutorial, we will guide you through the installation of Gitblit on NixOS Latest.

Prerequisites

Before starting with the installation process, ensure that you have the following requirements:

Step 1: Update the System

Ensure that the system is fully updated using the following command:

sudo nixos-rebuild switch --upgrade

Step 2: Install Java Development Kit

Gitblit is a Java-based application, so you need to install Java Development Kit. Run the following command to install it:

sudo nix-env -i openjdk11

Step 3: Download and Install Gitblit

To download Gitblit's latest version, navigate to its official website, and download the appropriate version. In this tutorial, we will download Gitblit 1.9.2.

wget https://github.com/gitblit/gitblit/releases/download/v1.9.2/gitblit-1.9.2.tar.gz

Extract the downloaded file using the following command:

tar -xzvf gitblit-1.9.2.tar.gz

Next, create a new directory to store Gitblit files:

sudo mkdir /opt/gitblit

Now, copy the extracted files to the newly created directory using the following command:

sudo cp -r gitblit-1.9.2/* /opt/gitblit

Step 4: Create a User for Gitblit

Create a new user account dedicated to Gitblit:

sudo useradd -r -s /bin/false gitblit

Set the ownership and permissions of the Gitblit directory to the newly created user:

sudo chown -R gitblit:gitblit /opt/gitblit
sudo chmod -R 755 /opt/gitblit

Step 5: Configure Gitblit

Copy the example Gitblit configuration file to the configuration directory:

sudo cp /opt/gitblit-data/gitblit.properties.example /opt/gitblit-data/gitblit.properties

Edit the gitblit.properties file using your favorite text editor:

sudo vim /opt/gitblit-data/gitblit.properties

Update the following properties:

server.httpPort = 80
web.enableRpcServlet = true
web.enableRpcManagement = true
web.enableRpcAdministration = true
web.enableGroovyServlet = true
web.enableActivityCache = true
web.enableRpcForwarding = true
security.allowManagement = true
web.passwd.user = admin
web.passwd.admin = admin

Save and close the file.

Step 6: Create a Systemd Service File

Create a new service file for Gitblit:

sudo vim /etc/systemd/system/gitblit.service

Add the following contents to the file:

[Unit]
Description=Gitblit Service
After=syslog.target

[Service]
Type=simple
ExecStart=/usr/bin/java -server -Xmx512m -jar /opt/gitblit/gitblit.jar --baseFolder /opt/gitblit-data
User=gitblit
Group=gitblit
WorkingDirectory=/opt/gitblit
Restart=always

[Install]
WantedBy=multi-user.target

Save and close the file.

Start and enable the Gitblit service:

sudo systemctl start gitblit
sudo systemctl enable gitblit

Step 7: Test Gitblit

You can now access Gitblit's web interface by navigating to your server's IP address or domain name in a web browser. Login using the default username and password, which is "admin" for both.

http://your_ip_address

That's it, you have successfully installed and configured Gitblit on NixOS Latest.

Conclusion

In this tutorial, we have guided you through the installation of Gitblit on NixOS Latest. You can now set up Git repositories and start managing them through Gitblit's web interface. If you face any issues during the installation process, don't hesitate to take a look at the Gitblit documentation or reach out to the community for support.

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!