Pinning home-manager
Packages
You update your system and now a application that you depend on no longer works as expected...
In any normal circumstance you are either sol
, or you uninstall and reinstall a backdated version if that's even possible.
But wait, you use home-manager
so instead of being at the whim of your package manager lets just pin the application to a specific version.
Normal Install
Let's use VS Code as our example. In any normal circumstances when using home-manager
you would use programs.
and enable what software you are interested in.
{ pkgs, ... }:
{
programs.vscode = {
enable = true;
};
}
This is usually ideal and would install the latest version of the software and with each update pull the newest version and apply it. But what happens when the software you rely on changes from right under you? Maybe there are random crashes, the company in control adds tracking and analytics, or a set of features you need silently fail now. Whatever the case, pinning an older version that was working prior to the update is needed.
Pinned Installed
First step is to select the build version of the software. You can go directly to GitHub or any site that distributes the archive of the build. I typically use lazamar.co.uk to search for package URLs. Once you identify the build version you require, use nix-prefetch-url --type sha256
to retrieve and hash the software package.
{ pkgs, ... }:
let
# Pinned v:1.101.0 VS Code
# nix-prefetch-url --type sha256 https://github.com/NixOS/nixpkgs/archive/1c1c9b3f5ec0421eaa0f22746295466ee6a8d48f.tar.gz
pinnedVSCode = import (fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/1c1c9b3f5ec0421eaa0f22746295466ee6a8d48f.tar.gz";
sha256 = "0szvq1swpzyjmyyw929ngxy1khdnd9ba96qds2bm6l6kg4iq3cq0";
}) {
system = pkgs.stdenv.hostPlatform.system;
config = { allowUnfree = true; };
};
# nix-prefetch-url --type sha256 https://marketplace.visualstudio.com/_apis/public/gallery/publishers/GitHub/vsextensions/copilot/1.342.0/vspackage
copilot.backdate = pkgs.vscode-utils.extensionFromVscodeMarketplace {
name = "copilot";
publisher = "github";
version = "1.342.0";
sha256 = "0kl1qkp47270g9rj9dmm297ydr2xzfp80wsbjdcd623wm1022p7k";
};
# nix-prefetch-url --type sha256 https://marketplace.visualstudio.com/_apis/public/gallery/publishers/GitHub/vsextensions/copilot-chat/0.28.5/vspackage
copilot.chat.backdate = pkgs.vscode-utils.extensionFromVscodeMarketplace {
name = "copilot-chat";
publisher = "github";
version = "0.28.5";
sha256 = "0wgr7bdn22l7r5qkxkr45nxqg234132qk6i4sd9qas1ihn8f45mk";
};
in
{
programs.vscode = {
enable = true;
package = pinnedVSCode.vscode;
profiles.default.extensions = with pkgs.vscode-extensions; [
# github.copilot
# github.copilot-chat
copilot.backdate
copilot.chat.backdate
];
};
}
In the above example we have pinned both VS Code and two extensions. Under the programs.
section we can now refer to our defined packages in the let
statement. ✨Ta-Da! You can now update your system without the worry of breaking the software you rely on.