Use nixpkgs from flake.lock and support attrs when importing bscpkgs

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 <rodrigo.arias@bsc.es>
This commit is contained in:
Aleix Boné 2025-02-28 13:23:28 +01:00 committed by Rodrigo Arias Mallo
parent 9d1944c658
commit 43d32ac16d
2 changed files with 15 additions and 16 deletions

View File

@ -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; }
)

View File

@ -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 <url>`
sha256 = "sha256-de9KYi8rSJpqvBfNwscWdalIJXPo8NjdIZcEJum1mH0=";
}