From 43d32ac16d930f733041478bbcc1c7125a208664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Bon=C3=A9?= Date: Fri, 28 Feb 2025 13:23:28 +0100 Subject: [PATCH] Use nixpkgs from flake.lock and support attrs when importing bscpkgs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes `nix-build` and friends use the current flake lock instead of the outdated pinned version we had in `./nixpkgs.nix` With this, `nix-build -A ovni` and `nix build .#ovni` should produce the same result. This will fail if the flake nixpkgs input does not come from NixOS/nixpkgs. We could use edolstra/flake-compat instead, but it's overkill imho. Additionally, I made default.nix behave like nixpkgs, so that we can import bscpkgs à la nixpkgs (Apply overlays and other options that nixpkgs accepts): ```nix let pkgs = import bscpkgs { inherit system; }; in <...> ``` Reviewed-by: Rodrigo Arias Mallo --- default.nix | 22 +++++++++++++++------- nixpkgs.nix | 9 --------- 2 files changed, 15 insertions(+), 16 deletions(-) delete mode 100644 nixpkgs.nix diff --git a/default.nix b/default.nix index a28f7599..14c06c63 100644 --- a/default.nix +++ b/default.nix @@ -1,11 +1,19 @@ let bscOverlay = import ./overlay.nix; - # Pin the nixpkgs - nixpkgsPath = import ./nixpkgs.nix; - - pkgs = import nixpkgsPath { - overlays = [ bscOverlay ]; + # read flake.lock and determine revision from there + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + inherit (lock.nodes.nixpkgs.locked) rev narHash; + fetchedNixpkgs = builtins.fetchTarball { + url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz"; + sha256 = narHash; }; - -in pkgs +in +{ overlays ? [ ] +, nixpkgs ? fetchedNixpkgs +, ... +}@attrs: +import nixpkgs ( + (builtins.removeAttrs attrs [ "overlays" "nixpkgs" ]) // + { overlays = [ bscOverlay ] ++ overlays; } +) diff --git a/nixpkgs.nix b/nixpkgs.nix deleted file mode 100644 index 20756970..00000000 --- a/nixpkgs.nix +++ /dev/null @@ -1,9 +0,0 @@ -let - commit = "e4ad989506ec7d71f7302cc3067abd82730a4beb"; -in builtins.fetchTarball { - # Descriptive name to make the store path easier to identify - name = "nixpkgs-${commit}"; - url = "https://github.com/nixos/nixpkgs/archive/${commit}.tar.gz"; - # Hash obtained using `nix-prefetch-url --unpack ` - sha256 = "sha256-de9KYi8rSJpqvBfNwscWdalIJXPo8NjdIZcEJum1mH0="; -}