Method to use newer packages until the channel catches up?

Sometimes the stable channel doesn’t have a package that’s up to date and I’d like to use a newer one until the channel catches up or surpasses it.

Right now, I have to manually keep that in check after I do a nixos-rebuild switch --upgrade by opening the program and periodically checking the version. Of course this isn’t maintainable for a larger set of packages, so I’m wondering if somebody has already solved this.

Example

{ pkgs, lib, ...}:

let
    unstable-pkgs = import <nixos-unstable> {};
    master-pkgs = import ( pkgs.fetchFromGitHub {
        owner = "NixOS";
        repo = "nixpkgs";
        rev = "master";
        sha256 = "sha256-cl4W4evuqbwH4LYpeS1+IPg9dJENW06PU3NAlFkB8Es=";
    }) {};
in {
        environment.systemPackages = with pkgs; [
            rocketchat-desktop
            unstable-pkgs.element-desktop
            master-pkgs.signal-desktop
        ];
}

signal-desktop is 6.5.1 in the pinned master-pkgs and 6.3.0 in pkgs. I have to manually check the version number and remove the pin once the version number changes. This isn’t the only pinned package of course…

you could do (if (lib.versionOlder hello.version master-pkgs.hello.version ) then master-pkgs.hello else hello) - you’d probably make that into a function, too

Thank you! That was the tip I needed. I wrote this simple function for my uses

{ pkgs, lib, ...}:
{
    /**                                                                                     
    Use a package from another repository,
     until the version in the default channel (pkgs) is newer than the custom package.

    Useful when using a newer package from another repo until the default channel catches up
    */                                                                                      
    useCustomPackageWhileNewer = packageName: packages: let                                 
        customPackage = builtins.getAttr packageName packages;                              
        channelPackage = builtins.getAttr packageName pkgs;                                 
        customIsOlder = lib.versionOlder customPackage.version channelPackage.version;      
    in if customIsOlder then (throw "Remove pin for ${packageName}") else customPackage;    
}                                                                                           
1 Like

@wamserma Cool idea! and @UefiPls Cool function too.

1 Like