Compare commits

..

2 commits

Author SHA1 Message Date
870bbb1f37 i cried 2026-02-18 17:24:28 +10:00
0c5387fd61 nixpkgs.channels disregards contextName 2026-02-17 17:27:31 +10:00
3 changed files with 52 additions and 59 deletions

View file

@ -197,8 +197,8 @@ in {
inherit root base; inherit root base;
inherit (node) system; inherit (node) system;
_cerulean = { _cerulean = {
inherit inputs userArgs; inherit inputs userArgs ceruleanArgs;
args = ceruleanArgs; specialArgs = userArgs // ceruleanArgs;
}; };
}; };
specialArgs = assert (userArgs specialArgs = assert (userArgs
@ -209,7 +209,7 @@ in {
`specialArgs` are like super important to Cerulean my love... </3 `specialArgs` are like super important to Cerulean my love... </3
But `args.${argName}` is a reserved argument name :( But `args.${argName}` is a reserved argument name :(
'')); ''));
userArgs // ceruleanArgs; ceruleanArgs._cerulean.specialArgs;
in in
lib.nixosSystem { lib.nixosSystem {
inherit (node) system; inherit (node) system;

View file

@ -25,21 +25,21 @@
pathExists pathExists
; ;
in { in {
config = { home-manager = {
home-manager = { users =
users = config.users.users
config.users.users |> attrNames
|> attrNames |> filter (x: pathExists (root + "/homes/${x}"))
|> filter (x: pathExists (root + "/homes/${x}")) |> (x:
|> (x: lib.genAttrs x (y: import (root + "/homes/${y}"))); lib.genAttrs x (y:
import (root + "/homes/${y}")));
extraSpecialArgs = _cerulean.args; extraSpecialArgs = _cerulean.specialArgs;
sharedModules = [ sharedModules = [
# user configuration # user configuration
(import (root + "/nixpkgs.nix")) (import (root + "/nixpkgs.nix"))
# options declarations # options declarations
(import ./nixpkgs.nix (args // {contextName = "homes";})) (import ./nixpkgs.nix (args // {contextName = "homes";}))
]; ];
};
}; };
} }

View file

@ -26,74 +26,67 @@
cfg = config.nixpkgs.channels; cfg = config.nixpkgs.channels;
in { in {
options.nixpkgs.channels = lib.mkOption { options.nixpkgs.channels = lib.mkOption {
type = lib.types.attrsOf (lib.types.attrs); type = lib.types.attrs;
default = {}; default = {};
description = "Declare package repositories per module context (nixos, home-manager, etc)"; description = "Declare package repositories";
example = { example = {
"homes" = { "pkgs" = {
"pkgs" = { source = "inputs.nixpkgs";
source = "inputs.nixpkgs"; system = "x86-64-linux";
system = "x86-64-linux"; config = {
config = { allowUnfree = true;
allowUnfree = true; allowBroken = false;
allowBroken = false;
};
}; };
"upkgs" = { };
source = "inputs.nixpkgs-unstable"; "upkgs" = {
system = "x86-64-linux"; source = "inputs.nixpkgs-unstable";
config = { system = "x86-64-linux";
allowUnfree = true; config = {
allowBroken = false; allowUnfree = false;
}; allowBroken = true;
}; };
}; };
}; };
}; };
config = let config = let
# TODO: use lib.types.submodule to restrict what options
# TODO: can be given to `nixpkgs.channels.${moduleName}.${name}`
decl =
cfg.${contextName} or cfg.default;
repos = repos =
decl cfg
|> (xs: removeAttrs xs ["default"])
|> mapAttrs ( |> mapAttrs (
name: args: name: args:
lib.mkForce ( lib.mkForce (
assert args ? source assert args ? source
|| abort '' || abort ''
${toString ./.} `nixpkgs.channels.${name}` missing required attribute "source"
`nixpkgs.channels.${contextName}.${name}` missing required attribute "source"
''; '';
((removeAttrs args ["source"]) import args.source ({inherit system;} // (removeAttrs args ["source"]))
// {inherit system;})
|> import args.source
) )
); );
# XXX: TODO: would it work to use `base` instead of having default?
defaultPkgs =
cfg.default or (throw ''
Your `nixpkgs.nix` file does not declare a default package source.
Ensure you set `nixpkgs.channels.*.default = ...;`
'');
in { in {
# NOTE: _module.args is a special option that allows us to # NOTE: _module.args is a special option that allows us to
# NOTE: set extend specialArgs from inside the modules. # NOTE: set extend specialArgs from inside the modules.
_module.args = repos; _module.args = repos;
nixpkgs = let nixpkgs =
defaultPkgs =
decl.default or (throw ''
Your `nixpkgs.nix` file does not declare a default package source.
Ensure you set `nixpkgs.channels.*.default = ...;`
'');
in
if contextName == "hosts" if contextName == "hosts"
then { then
flake.source = lib.mkOverride 200 defaultPkgs.source; # DEBUG: defaultPkgs
config = lib.mkOverride 200 defaultPkgs.config; {
} flake.source = lib.mkOverride 200 (defaultPkgs.source or null);
overlays = lib.mkOverride 200 (defaultPkgs.overlays or {});
config = lib.mkOverride 200 (defaultPkgs.config or {});
}
else if contextName == "homes" else if contextName == "homes"
then { then {
# XXX: XXX: XXX: OH OH OH OMG, its because aurora never defines pkgs
config = lib.mkOverride 200 (defaultPkgs.config or {}); config = lib.mkOverride 200 (defaultPkgs.config or {});
# XXX: WARNING: TODO: modify options so overlays must always be given as the correct type
overlays = lib.mkOverride 200 (defaultPkgs.overlays or []); overlays = lib.mkOverride 200 (defaultPkgs.overlays or []);
} }
else {}; else {};