NixOS Installation

This guide covers setting up Google Gemini on NixOS, a purely functional Linux distribution that offers reproducible system configurations through the Nix package manager.

Advantages of NixOS for Gemini Deployments

NixOS provides several benefits for DevOps professionals working with AI tools like Gemini:

  • Reproducible environments: Identical deployment across all systems

  • Declarative configuration: System configuration as code

  • Isolated dependencies: Prevent conflicts between different Python versions or libraries

  • Rollbacks: Easy recovery if something breaks

  • Development shells: Isolated environments for different AI projects

Installation Methods

Nix Flakes provide a modern, reproducible approach to Nix packages.

  1. First, ensure flakes are enabled in your NixOS configuration:

# In your configuration.nix
{ pkgs, ... }: {
  nix = {
    package = pkgs.nixFlakes;
    extraOptions = ''
      experimental-features = nix-command flakes
    '';
  };
}
  1. Create a new flake for your Gemini project:

  1. Create a flake.nix file:

  1. Enter the development shell:

Method 2: Using configuration.nix (System-wide)

Add the following to your configuration.nix:

Then rebuild your system:

Method 3: Using nix-shell (Project-specific)

Create a shell.nix file in your project directory:

Activate it with:

Authentication Configuration

Managing API Keys Securely with NixOS

For development, use environment variables:

For system-wide deployment, use NixOS secrets management:

Service Integration

Creating a Gemini Service with systemd in NixOS

Verification & Testing

Test your setup with a simple script:

Save as test.py and run:

Last updated