bew
October 23, 2021, 7:50am
3
I personally don’t like the global registry, with its imperative way of management.
Instead I remove the global registry and declaratively setup the user registry.
To remove the global registry, set the flake-registry
option in nix.conf
to an empty registry:
# vim:ft=conf:
# Path or URI for the global flake registry
# => Setting it to empty needs https://github.com/NixOS/nix/issues/4874
# => Setting it to a relative path needs https://github.com/NixOS/nix/issues/4875
flake-registry = /home/lesell_b/.config/nix/empty-global-flake-registry.json
# NOTE: User registry entries are stored in ~/.config/nix/registry.json, this
# file is managed by my home Flake.
# (read more in ./../nix-home/modules/nix-registry.nix)
# Enable cool stuff!
# (NOTE: on multi-user install, the user needs to be trusted)
experimental-features = nix-command flakes
# NOTE: if you want to enable 'ca-references' to be able to use `nix profile install` command,
# know that `nix-env` command will stop working, and that home-manager is ONLY compatible with
# `nix-env` (at time ot writing).
(an empty registry looks like: { "version": 2, "flakes": [] }
)
To configure the user registry, it is stored in ~/.config/nix/registry.json
and I configure it with a home manager module of my own:
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.nixRegistry;
in {
options = {
nixRegistry.indirectFlakes = mkOption {
# NOTE: types.uniq ensures that multiple definitions of the same flake will not try to merge
# them, it will raise an error instead.
type = types.attrsOf (types.uniq types.attrs);
default = {};
description = ''
Attrset associating a flake name to flake reference (as an attrset not as a string).
'';
example = {
thepkgs = { type = "path"; path = nixpkgs.outPath; };
};
};
This file has been truncated. show original
And I use it like this:
To declare a pkgs
flake (pinned to the nixpkgs of my home flake) and an unstable
user flake (on the github’s nixpkgs-unstable
branch)
Hope it helps someone
4 Likes