flake: remove nonstandard top-level flake attrs

Silences warnings in `nix flake check`.

- Define `mkNbPkgs` under attr `lib`.
  `lib` still triggers a warning, but it is expected to be a standard
  flake attr in a future Nix release.

- Define `nbPkgs` under attr `legacyPackages`.
  This also has the advantage to make its contents more easily
  accessible via the nix CLI. Example:
  nix eval nix-bitcoin#nbPkgs.modulesPkgs.clightning.version
This commit is contained in:
Erik Arvstedt 2021-12-27 16:58:14 +01:00
parent dc382b8b67
commit d69524143b
No known key found for this signature in database
GPG Key ID: 33312B944DD97846

View File

@ -15,22 +15,24 @@
supportedSystems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ]; supportedSystems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
in in
rec { rec {
lib = {
mkNbPkgs = { mkNbPkgs = {
system system
, pkgs ? import nixpkgs { inherit system; } , pkgs ? import nixpkgs { inherit system; }
, pkgsUnstable ? import nixpkgsUnstable { inherit system; } , pkgsUnstable ? import nixpkgsUnstable { inherit system; }
}: }:
import ./pkgs { inherit pkgs pkgsUnstable; }; import ./pkgs { inherit pkgs pkgsUnstable; };
};
overlay = final: prev: let overlay = final: prev: let
nbPkgs = mkNbPkgs { inherit (final) system; pkgs = final; }; nbPkgs = lib.mkNbPkgs { inherit (final) system; pkgs = final; };
in removeAttrs nbPkgs [ "pinned" "nixops19_09" "krops" ]; in removeAttrs nbPkgs [ "pinned" "nixops19_09" "krops" ];
nixosModules = { nixosModules = {
# Uses the default system pkgs for nix-bitcoin.pkgs # Uses the default system pkgs for nix-bitcoin.pkgs
withSystemPkgs = { pkgs, ... }: { withSystemPkgs = { pkgs, ... }: {
imports = [ ./modules/modules.nix ]; imports = [ ./modules/modules.nix ];
nix-bitcoin.pkgs = (mkNbPkgs { inherit (pkgs) system; inherit pkgs; }).modulesPkgs; nix-bitcoin.pkgs = (lib.mkNbPkgs { inherit (pkgs) system; inherit pkgs; }).modulesPkgs;
}; };
# Uses the nixpkgs version locked by this flake for nix-bitcoin.pkgs. # Uses the nixpkgs version locked by this flake for nix-bitcoin.pkgs.
@ -38,7 +40,7 @@
# locked and the system nixpkgs versions differ. # locked and the system nixpkgs versions differ.
withLockedPkgs = { config, ... }: { withLockedPkgs = { config, ... }: {
imports = [ ./modules/modules.nix ]; imports = [ ./modules/modules.nix ];
nix-bitcoin.pkgs = (mkNbPkgs { inherit (config.nixpkgs) system; }).modulesPkgs; nix-bitcoin.pkgs = (lib.mkNbPkgs { inherit (config.nixpkgs) system; }).modulesPkgs;
}; };
}; };
@ -51,6 +53,8 @@
let let
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
nbPkgs = self.lib.mkNbPkgs { inherit system pkgs; };
mkVMScript = vm: pkgs.writers.writeBash "run-vm" '' mkVMScript = vm: pkgs.writers.writeBash "run-vm" ''
set -euo pipefail set -euo pipefail
export TMPDIR=$(mktemp -d /tmp/nix-bitcoin-vm.XXX) export TMPDIR=$(mktemp -d /tmp/nix-bitcoin-vm.XXX)
@ -59,8 +63,6 @@
QEMU_OPTS="-smp $(nproc) -m 1500" ${vm}/bin/run-*-vm QEMU_OPTS="-smp $(nproc) -m 1500" ${vm}/bin/run-*-vm
''; '';
in rec { in rec {
nbPkgs = self.mkNbPkgs { inherit system pkgs; };
packages = flake-utils.lib.flattenTree (removeAttrs nbPkgs [ packages = flake-utils.lib.flattenTree (removeAttrs nbPkgs [
"pinned" "modulesPkgs" "nixops19_09" "krops" "generate-secrets" "netns-exec" "pinned" "modulesPkgs" "nixops19_09" "krops" "generate-secrets" "netns-exec"
]) // { ]) // {
@ -92,6 +94,11 @@
}).vm; }).vm;
}; };
# Allow accessing the whole nested `nbPkgs` attrset (including `modulesPkgs`)
# via this flake.
# `packages` is not allowed to contain nested pkgs attrsets.
legacyPackages = { inherit nbPkgs; };
defaultApp = apps.vm; defaultApp = apps.vm;
apps = { apps = {