Talk: FAQ/Pinning Nixpkgs
From NixOS Wiki
< Talk:FAQ
I would like to achieve something like a lock file, but optionally used.
# This allows overriding pkgs by passing `--arg production ...` { production ? false, nixpkgs ? import <nixpkgs> {} }: let # Look here for information about how to generate `nixpkgs-version.json`. # → https://nixos.wiki/wiki/FAQ/Pinning_Nixpkgs pinned = builtins.fromJSON (builtins.readFile ./nixpkgs.lock); inherit (pinned) url rev; ref = "nixos-unstable"; # Load packages from the pinned version. pinnedNixpkgs = import (builtins.fetchGit { inherit ref url rev; }) {}; # Update ./nixpkgs.lock nixpkgsUpdate = nixpkgs.writeScriptBin "update-nixpkgs" '' #!/bin/sh ${nixpkgs.nix-prefetch-git}/bin/nix-prefetch-git ${url} refs/heads/${ref} > nixpkgs.lock ''; pkgs = if production then pinnedNixpkgs else nixpkgs; in with pkgs; mkShell { buildInputs = [ nodejs nixpkgsUpdate ]; }
Obviously this doens't work, but its close... not sure what I missed