nixpkgs/nixos/modules/config/nix-flakes.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

111 lines
2.9 KiB
Nix

/*
Manages the flake registry.
See also
- ./nix.nix
- ./nix-channel.nix
*/
{ config, lib, ... }:
let
inherit (lib)
filterAttrs
literalExpression
mapAttrsToList
mkDefault
mkIf
mkOption
types
;
cfg = config.nix;
in
{
options = {
nix = {
registry = mkOption {
type = types.attrsOf (
types.submodule (
let
referenceAttrs =
with types;
attrsOf (oneOf [
str
int
bool
path
package
]);
in
{ config, name, ... }:
{
options = {
from = mkOption {
type = referenceAttrs;
example = {
type = "indirect";
id = "nixpkgs";
};
description = "The flake reference to be rewritten.";
};
to = mkOption {
type = referenceAttrs;
example = {
type = "github";
owner = "my-org";
repo = "my-nixpkgs";
};
description = "The flake reference {option}`from` is rewritten to.";
};
flake = mkOption {
type = types.nullOr types.attrs;
default = null;
example = literalExpression "nixpkgs";
description = ''
The flake input {option}`from` is rewritten to.
'';
};
exact = mkOption {
type = types.bool;
default = true;
description = ''
Whether the {option}`from` reference needs to match exactly. If set,
a {option}`from` reference like `nixpkgs` does not
match with a reference like `nixpkgs/nixos-20.03`.
'';
};
};
config = {
from = mkDefault {
type = "indirect";
id = name;
};
to = mkIf (config.flake != null) (
mkDefault (
{
type = "path";
path = config.flake.outPath;
}
// filterAttrs (n: _: n == "lastModified" || n == "rev" || n == "narHash") config.flake
)
);
};
}
)
);
default = { };
description = ''
A system-wide flake registry.
'';
};
};
};
config = mkIf cfg.enable {
environment.etc."nix/registry.json".text = builtins.toJSON {
version = 2;
flakes = mapAttrsToList (n: v: { inherit (v) from to exact; }) cfg.registry;
};
};
}