add support for multiple pkg channels

This commit is contained in:
do butterflies cry? 2026-02-13 12:38:53 +10:00
parent b56c07bc4c
commit 542f2ff3f4
4 changed files with 111 additions and 115 deletions

View file

@ -12,10 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
{ {
self,
this, this,
nixpkgs,
nixpkgs-unstable,
nt, nt,
lib, lib,
deploy-rs, deploy-rs,
@ -42,6 +39,11 @@
mapNodes mapNodes
; ;
inherit
(nt)
findImport
;
templateNexus = let templateNexus = let
inherit inherit
(nt.naive.terminal) (nt.naive.terminal)
@ -54,11 +56,8 @@
Ensure `nexus.${path}` exists under your call to `cerulean.mkNexus`. Ensure `nexus.${path}` exists under your call to `cerulean.mkNexus`.
''); '');
in { in {
overlays = [];
extraModules = []; extraModules = [];
specialArgs = Terminal {}; specialArgs = Terminal {};
# XXX: WARNING: extraPkgConfig is a terrible solution (but im lazy for now)
extraPkgConfig = Terminal {};
groups = Terminal {}; groups = Terminal {};
nodes = Terminal {}; nodes = Terminal {};
@ -71,7 +70,8 @@
isAttrs g isAttrs g
|| throw '' || throw ''
Cerulean Nexus groups must be provided as attribute sets, got "${typeOf g}" instead! Cerulean Nexus groups must be provided as attribute sets, got "${typeOf g}" instead!
Ensure all the `groups` definitions are attribute sets under your call to `cerulean.mkNexus`. Ensure all the group definitions are attribute sets under your call to `cerulean.mkNexus`.
NOTE: Groups can be accessed via `self.groups.PATH.TO.YOUR.GROUP`
''; '';
delegate = parent: gName: g: let delegate = parent: gName: g: let
result = result =
@ -126,38 +126,8 @@
in in
final; final;
importOverlays = root: let getGroupModules = root: nodeName: node:
path = findImport (root + "/overlay"); assert isList node.groups
in
if pathExists path
then import path
else [];
# XXX: TODO: create a function in NixTypes that handles this instead
findImport = path:
if pathExists path
then path
else if pathExists (path + "default.nix")
then path + "/default.nix"
else path + ".nix";
in {
mkNexus = root: outputsBuilder: let
decl = parseDecl outputsBuilder;
inherit
(decl)
nexus
;
customOutputs = removeAttrs decl ["nexus"];
outputs = rec {
nixosConfigurations = mapNodes nexus.nodes (
nodeName: node:
lib.nixosSystem {
system = node.system;
modules = let
host = findImport (root + "/hosts/${nodeName}");
groups = assert isList node.groups
|| throw '' || throw ''
Cerulean Nexus node "${nodeName}" does not declare group membership as a list, got "${typeOf node.groups}" instead! Cerulean Nexus node "${nodeName}" does not declare group membership as a list, got "${typeOf node.groups}" instead!
Ensure `nexus.nodes.${nodeName}.groups` is a list under your call to `cerulean.mkNexus`. Ensure `nexus.nodes.${nodeName}.groups` is a list under your call to `cerulean.mkNexus`.
@ -199,40 +169,33 @@ in {
|> nt.prim.unique |> nt.prim.unique
# ignore missing groups # ignore missing groups
|> filter pathExists; |> filter pathExists;
in in {
[../nixos-module host] mkNexus = root: outputsBuilder: let
++ groups decl = parseDecl outputsBuilder;
++ node.extraModules
++ nexus.extraModules;
# nix passes these to every single module inherit
specialArgs = let (decl)
# XXX: NOTE: REF: https://github.com/NixOS/nixpkgs/blob/master/flake.nix#L57 nexus
# XXX: NOTE: lib.nixosSystem is defined here ^^^^ ;
pkgConfig = customOutputs = removeAttrs decl ["nexus"];
{
inherit (node) system; outputs = rec {
# XXX: WARNING: TODO: i've stopped caring nixosConfigurations = mapNodes nexus.nodes (
# XXX: WARNING: TODO: just figure out a better solution to pkgConfig nodeName: node: let
config.allowUnfree = false; nixosDecl = lib.nixosSystem {
config.allowBroken = false; system = node.system;
overlays = specialArgs =
self.overlays
++ nexus.overlays
++ node.overlays
++ importOverlays root;
}
// nexus.extraPkgConfig # TODO: import
// node.extraPkgConfig; # TODO: import
in
nexus.specialArgs nexus.specialArgs
// node.specialArgs // node.specialArgs
// { // {inherit root;};
inherit root; modules =
pkgs = import nixpkgs pkgConfig; [../nixos-module (findImport (root + "/hosts/${nodeName}"))]
upkgs = import nixpkgs-unstable pkgConfig; ++ getGroupModules root nodeName node
++ node.extraModules
++ nexus.extraModules;
}; };
} in
nixosDecl
); );
deploy.nodes = mapNodes nexus.nodes (nodeName: node: let deploy.nodes = mapNodes nexus.nodes (nodeName: node: let

View file

@ -31,8 +31,6 @@ in rec {
extraModules = []; extraModules = [];
specialArgs = Terminal {}; specialArgs = Terminal {};
overlays = []; overlays = [];
# XXX: WARNING: extraPkgConfig is a terrible solution (but im lazy for now)
extraPkgConfig = Terminal {};
deploy = { deploy = {
user = "root"; user = "root";

View file

@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
{deploy-rs, ...}: { {deploy-rs}: {
imports = [ imports = [
./nixpkgs.nix ./nixpkgs.nix
./home-manager.nix ./home-manager.nix

View file

@ -12,13 +12,24 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
{ {
nt,
lib, lib,
config, config,
... ...
}: let }: let
cfg = config.pkgrepo; inherit
(builtins)
mapAttrs
;
inherit
(nt)
flip
;
cfg = config.pkgsrc;
in { in {
options.pkgrepo = lib.mkOption { options.pkgsrc = lib.mkOption {
type = lib.types.attrsOf lib.types.attrs; type = lib.types.attrsOf lib.types.attrs;
default = {}; default = {};
description = "Declare and import custom package repositories."; description = "Declare and import custom package repositories.";
@ -34,15 +45,39 @@ in {
}; };
}; };
config.nixpkgs = config = let
lib.mkIf (cfg ? pkgs) # TODO: use lib.types.submodule to restrict what options
(let # TODO: can be given to pkgsrc
pkgs = cfg.pkgs; repos =
in cfg
lib.mkForce ( |> mapAttrs (
(builtins.removeAttrs pkgs ["source"]) name: args:
// { assert args ? source
flake.source = pkgs.source; || abort ''
} ${./.}
)); `pkgsrc.${name} missing required attribute "source"`
'';
args
|> flip removeAttrs ["source"]
|> import args.source
);
in {
# NOTE: _module.args is a special option that allows us to
# NOTE: set extend specialArgs from inside the modules.
# "pkgs" is unique since the nix module system already handles it
_module.args =
removeAttrs repos ["pkgs"];
# nixpkgs =
# lib.mkIf (cfg ? pkgs)
# (let
# pkgs = cfg.pkgs;
# in
# lib.mkForce (
# (removeAttrs pkgs ["source"])
# // {
# flake.source = pkgs.source;
# }
# ));
};
} }