Talk:FAQ/Pinning Nixpkgs: Difference between revisions
< Talk:FAQ
imported>Expelledboy Thinking to add a lock file example, but failing |
No edit summary |
||
Line 11: | Line 11: | ||
let | let | ||
# Look here for information about how to generate `nixpkgs-version.json`. | # Look here for information about how to generate `nixpkgs-version.json`. | ||
# → https://nixos. | # → https://wiki.nixos.org/wiki/FAQ/Pinning_Nixpkgs | ||
pinned = builtins.fromJSON (builtins.readFile ./nixpkgs.lock); | pinned = builtins.fromJSON (builtins.readFile ./nixpkgs.lock); | ||
inherit (pinned) url rev; | inherit (pinned) url rev; |
Latest revision as of 18:09, 3 April 2024
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://wiki.nixos.org/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