cerulean/nix/nixos/nixpkgs.nix

96 lines
2.4 KiB
Nix
Raw Normal View History

2026-02-19 14:38:52 +10:00
# Copyright 2025-2026 _cry64 (Emile Clark-Boman)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
{
2026-02-18 20:13:43 +10:00
base,
lib,
2026-02-13 19:32:22 +10:00
system,
config,
2026-02-13 19:32:22 +10:00
contextName,
...
}: let
2026-02-13 12:38:53 +10:00
inherit
(builtins)
mapAttrs
;
2026-02-13 19:32:22 +10:00
cfg = config.nixpkgs.channels;
in {
2026-02-13 19:32:22 +10:00
options.nixpkgs.channels = lib.mkOption {
type = lib.types.attrs;
default = {};
description = "Declare package repositories";
example = {
"npkgs" = {
source = "inputs.nixpkgs";
system = "x86-64-linux";
config = {
allowUnfree = true;
allowBroken = false;
2026-02-13 19:32:22 +10:00
};
};
"upkgs" = {
source = "inputs.nixpkgs-unstable";
system = "x86-64-linux";
config = {
allowUnfree = false;
allowBroken = true;
};
};
};
};
2026-02-13 12:38:53 +10:00
config = let
repos =
cfg
|> (xs: removeAttrs xs ["base"])
2026-02-13 12:38:53 +10:00
|> mapAttrs (
name: args:
2026-02-13 22:13:35 +10:00
lib.mkForce (
assert args ? source
|| abort ''
`nixpkgs.channels.${name}` missing required attribute "source"
2026-02-13 22:13:35 +10:00
'';
2026-02-18 17:24:28 +10:00
import args.source ({inherit system;} // (removeAttrs args ["source"]))
2026-02-13 22:13:35 +10:00
)
2026-02-13 12:38:53 +10:00
);
2026-02-18 17:24:28 +10:00
basePkgs = cfg.base or {};
2026-02-13 12:38:53 +10:00
in {
# NOTE: _module.args is a special option that allows us to
# NOTE: set extend specialArgs from inside the modules.
2026-02-18 20:13:36 +10:00
# WARNING: pkgs is a reserved specialArg
_module.args = removeAttrs repos ["pkgs" "base"];
2026-02-13 12:38:53 +10:00
nixpkgs = let
nixpkgsConfig = {
config = lib.mkForce (basePkgs.config or {});
overlays = lib.mkForce (basePkgs.overlays or []);
};
nixpkgsHostsConfig =
nixpkgsConfig
// {
flake.source = lib.mkForce base;
};
nixpkgsHomesConfig = lib.mkIf (!config.home-manager.useGlobalPkgs) nixpkgsConfig;
in
if contextName == "hosts"
then nixpkgsHostsConfig
2026-02-13 22:13:35 +10:00
else if contextName == "homes"
then nixpkgsHomesConfig
2026-02-13 19:32:22 +10:00
else {};
2026-02-13 12:38:53 +10:00
};
}