moonsn

moonsn

How to fix the version of a certain package in NixOS.

When executing nixos-rebuild in NixOS, the software is updated along with the specified nixpkgs version.

Although I am using the flake feature, I want most of the software to stay up to date in most cases, with only a few software versions that I need to fix.

Specifically, I have a NixOS running gitea, and I don't want to update the version of gitea when compiling this system.

sudo nixos-rebuild test --flake '.#gitea'

Solution:

There is a website for querying the nixpkgs commit corresponding to the package version: https://lazamar.co.uk/nix-versions/ with a hint code for pinning the package.

For example, if I need to pin gitea to version 1.18.5 of nixos-unstable:

let
     pkgs = import (builtins.fetchGit {
         # Descriptive name to make the store path easier to identify                
         name = "my-old-revision";                                                 
         url = "https://github.com/NixOS/nixpkgs/";                       
         ref = "refs/heads/nixos-unstable";                     
         rev = "64c27498901f104a11df646278c4e5c9f4d642db";                                           
     }) {};                                                                           

     myPkg = pkgs.gitea;
in

# Other code

# Modify the package used by the gitea service to the pinned package
services.gitea.package = myPkg
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.