Skip to content

Commit

Permalink
nix-flakes.nix: inherit from upstream nix-flakes.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
ShamrockLee committed Feb 17, 2024
1 parent 1685914 commit 8be0c07
Showing 1 changed file with 5 additions and 76 deletions.
81 changes: 5 additions & 76 deletions modules/environment/nix-flakes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# (Copyright (c) 2003-2022 Eelco Dolstra and the Nixpkgs/NixOS contributors,
# licensed under MIT License as well)

{ config, lib, pkgs, ... }:
{ config, lib, pkgs, nixpkgs, ... }:

with lib;

Expand All @@ -14,79 +14,8 @@ let
in

{
###### interface

options = {
nix = {
registry = mkOption {
type = types.attrsOf (types.submodule (
let
referenceAttrs = with types; attrsOf (oneOf [
str
int
bool
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</option> is rewritten to.";
};
flake = mkOption {
type = types.nullOr types.attrs;
default = null;
example = literalExpression "nixpkgs";
description = ''
The flake input <option>from</option> is rewritten to.
'';
};
exact = mkOption {
type = types.bool;
default = true;
description = ''
Whether the <option>from</option> reference needs to match exactly. If set,
a <option>from</option> reference like <literal>nixpkgs</literal> does not
match with a reference like <literal>nixpkgs/nixos-20.03</literal>.
'';
};
};
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 == "revCount" || n == "narHash")
config.flake);
};
}
));
default = { };
description = "A system-wide flake registry.";
};
};
};


###### implementation

config = {
environment.etc = {
"nix/registry.json".text = builtins.toJSON {
version = 2;
flakes = mapAttrsToList (_n: v: { inherit (v) from to exact; }) cfg.registry;
};
};
};

imports = [
# Use options and config from upstream nix-flakes.nix
"${nixpkgs}nixos/modules/config/nix-flakes.nix"
];
}

0 comments on commit 8be0c07

Please sign in to comment.