How to Install Cgit on NixOS Latest

Cgit is a web interface for Git repositories, enabling code browsing and commit history visualization. In this tutorial, we will guide you through the process of installing Cgit on NixOS Latest.

Prerequisites

Before proceeding with the installation, make sure that you have the following:

Step 1 - Install Cgit

First, let's install Cgit from the official Nix package manager:

$ sudo nix-env -iA nixos.cgit

This will download and install the latest version of Cgit and its dependencies.

Step 2 - Configure Cgit

Next, we need to configure Cgit by creating a custom configuration file at /etc/cgitrc. You can copy the default configuration file from /nix/store/<hash>/share/cgit/cgitrc. Replace with the actual hash of the installed package.

$ sudo cp /nix/store/<hash>/share/cgit/cgitrc /etc/cgitrc

Open the /etc/cgitrc file in a text editor and edit the cssurl, logo, clone-url, and virtual-root settings to match your system's configuration.

Step 3 - Configure Web Server

We need to configure our web server to serve Cgit. Below are the configuration files for Nginx and Apache.

Nginx Configuration

Create a new server block in your Nginx configuration at /etc/nginx/sites-enabled/cgit. Replace example.com with your domain name and /var/www/cgit with the path to your cgit installation.

server {
    listen 80;
    server_name example.com;

    access_log /var/log/nginx/cgit.access.log combined;
    error_log /var/log/nginx/cgit.error.log;

    root /var/www/cgit;

    location / {
        try_files $uri @cgit;
    }

    location @cgit {
        fastcgi_pass unix:/run/cgit.socket;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /nix/store/<hash>/bin/cgit.cgi;
        fastcgi_param PATH_INFO $uri;
    }
}

Reload Nginx configuration:

$ sudo systemctl reload nginx

Apache Configuration

Open the Apache configuration file at /etc/httpd/conf/httpd.conf and add the following code to enable CGI:

<Directory "/var/www/cgit">
    AllowOverride None
    Options +ExecCGI
    AddHandler cgi-script .cgi
    Require all granted
</Directory>

Then, add a virtual host block to point the Apache server to your cgit installation. Replace example.com with your domain name.

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/cgit

    ErrorLog /var/log/httpd/cgit.error.log
    CustomLog /var/log/httpd/cgit.access.log combined

    ScriptAlias /cgi-bin/ "/nix/store/<hash>/bin/"
</VirtualHost>

Reload Apache configuration:

$ sudo systemctl reload httpd

Step 4 - Test Cgit

Now that we have everything set up, let's test if Cgit is working properly. Visit your Cgit URL at http://example.com and you should see your Git repositories listed.

Conclusion

Cgit is an excellent web interface for Git repositories that is easy to install and configure on NixOS Latest. With its user-friendly interface, your team will be able to browse code and track changes without having to use the command line. Happy coding!

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!