Created
August 17, 2025 18:33
-
-
Save brianmcgee/99ed94ca521e0f4f635b4271037b2aa3 to your computer and use it in GitHub Desktop.
An example of pinning nixpkgs using flakes and a sample nixos configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| description = "An example of pinning nixpkgs"; | |
| inputs = { | |
| nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; | |
| nixpkgsPinned.url = "github:nixos/nixpkgs?rev=e07c1ba3ce542747dd0941a459b90259e228478d"; | |
| }; | |
| outputs = { self, nixpkgs, nixpkgsPinned, ... }: let | |
| # NOTE: this is a very 'flat' and vanilla flake. The structure might look a bit different if you're using flake-parts, | |
| # blueprint, flake-utils or any of the many approaches for structuring flakes. | |
| # The basic mechanics should remain the same regardless. | |
| # define our target system | |
| system = "x86_64-linux"; | |
| # shared config for nixpkgs instances | |
| config = { | |
| allowUnfree = true; | |
| }; | |
| # create our default instance | |
| pkgs = import nixpkgs { | |
| inherit system config; | |
| }; | |
| # create a pinned instance with the same system and config | |
| pkgsPinned = import nixpkgsPinned { | |
| inherit system config; | |
| }; | |
| in { | |
| # set the versions of davinci-resolve as packages of this flake for quick eval of version | |
| # you can check the versions quickly with: | |
| # - nix eval .#davinci-resolve-latest.version ("20.0.1") | |
| # - nix eval .#davinci-resolve-pinned.version ("20.0") | |
| packages.${system} = { | |
| davinci-resolve-latest = pkgs.davinci-resolve; | |
| davinci-resolve-pinned = pkgsPinned.davinci-resolve; | |
| }; | |
| # an example of how to use the default and pinned instances above in a nixos configuration | |
| nixosConfigurations.example = nixpkgs.lib.nixosSystem { | |
| inherit system; | |
| specialArgs = { | |
| inherit pkgsPinned; | |
| }; | |
| modules = [ | |
| { | |
| # this step is not strictly necessary | |
| # `nixpkgs.lib.nixosSystem` above will create a nixpkgs instance by default matching the version of | |
| # the nixpkgs instance | |
| # by passing our existing instance in we can shared it across nixos configurations and reduce a bit of | |
| # RAM when evaluating | |
| nixpkgs.pkgs = pkgs; | |
| # some basic info copied from another project to satisfy basic requirements of a nixos config | |
| boot = { | |
| growPartition = true; | |
| kernelParams = ["console=ttyS0"]; | |
| loader = { | |
| timeout = 0; | |
| grub.device = "/dev/vda"; | |
| }; | |
| }; | |
| fileSystems."/" = { | |
| device = "/dev/vda"; | |
| autoResize = true; | |
| fsType = "ext4"; | |
| }; | |
| } | |
| # each nixos module will now have the default `pkgs` arg and also a `pkgsPinned` arg we can use to reference | |
| # our pinned version of davinci-resolve | |
| ({ pkgs, pkgsPinned, ...}: { | |
| environment.systemPackages = [ | |
| # use our pinned package instead | |
| pkgsPinned.davinci-resolve | |
| ]; | |
| }) | |
| ]; | |
| }; | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment