fix nixpkgs.channels system

This commit is contained in:
do butterflies cry? 2026-02-13 19:32:22 +10:00
parent 7ad231ae5c
commit 52044bd998
7 changed files with 92 additions and 56 deletions

View file

@ -15,14 +15,19 @@
mix,
deploy-rs,
...
} @ inputs:
mix.newMixture inputs (mixture: {
} @ args:
mix.newMixture args (mixture: {
includes.public = [
./nexus
];
version = "0.1.0";
nixosModules = rec {
default = cerulean;
cerulean = ./nixos-module;
};
overlays = [
# build deploy-rs as a package not from the flake input,
# hence we can rely on a nixpkg binary cache.

View file

@ -11,8 +11,8 @@
# 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.
{mix, ...} @ inputs:
mix.newMixture inputs (mixture: {
{mix, ...} @ args:
mix.newMixture args (mixture: {
includes.public = [
./nodes.nix
./nexus.nix

View file

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
{
self,
this,
nt,
lib,
@ -184,15 +185,18 @@ in {
nodeName: node: let
nixosDecl = lib.nixosSystem {
system = node.system;
specialArgs = let
specialArgs =
nexus.specialArgs
// node.specialArgs
// {
inherit root;
inherit root specialArgs;
inherit (node) system;
};
in
specialArgs;
modules =
[../nixos-module (findImport (root + "/hosts/${nodeName}"))]
[self.nixosModules.default (findImport (root + "/hosts/${nodeName}"))]
++ (getGroupModules root nodeName node)
++ node.extraModules
++ nexus.extraModules;

View file

@ -11,9 +11,17 @@
# 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.
{deploy-rs, ...}: {
{
root,
deploy-rs,
...
} @ args: {
imports = [
./nixpkgs.nix
# user configuration
(import (root + "/nixpkgs.nix"))
# options declarations
(import ./nixpkgs.nix (args // {contextName = "hosts";}))
./home-manager.nix
];

View file

@ -15,15 +15,27 @@
root,
config,
lib,
specialArgs,
...
} @ args: {
} @ args: let
inherit
(builtins)
attrNames
filter
pathExists
;
in {
home-manager = {
users =
config.users.users
|> builtins.attrNames
|> builtins.filter (x: builtins.pathExists (root + "/homes/${x}"))
|> attrNames
|> filter (x: pathExists (root + "/homes/${x}"))
|> (x: lib.genAttrs x (y: import (root + "/homes/${y}")));
extraSpecialArgs = args;
extraSpecialArgs = specialArgs;
sharedModules = [
(import (root + "/nixpkgs.nix"))
(import ./nixpkgs.nix (args // {contextName = "homes";}))
];
};
}

View file

@ -12,9 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
{
nt,
lib,
system,
config,
contextName,
...
}: let
inherit
@ -22,18 +23,14 @@
mapAttrs
;
inherit
(nt)
flip
;
cfg = config.pkgsrc;
cfg = config.nixpkgs.channels;
in {
options.pkgsrc = lib.mkOption {
type = lib.types.attrsOf lib.types.attrs;
options.nixpkgs.channels = lib.mkOption {
type = lib.types.attrsOf (lib.types.attrs);
default = {};
description = "Declare and import custom package repositories.";
description = "Declare package repositories per module context (nixos, home-manager, etc)";
example = {
"homes" = {
"pkgs" = {
source = "inputs.nixpkgs";
system = "x86-64-linux";
@ -42,42 +39,52 @@ in {
allowBroken = false;
};
};
"upkgs" = {
source = "inputs.nixpkgs-unstable";
system = "x86-64-linux";
config = {
allowUnfree = true;
allowBroken = false;
};
};
};
};
};
# or abort ''
# `nixpkgs.channels.${contextName}` does not exist, but neither does `nixpkgs.channels.default`!
# A channel configuration must be declared for module context "${contextName}".
# ''
config = let
# TODO: use lib.types.submodule to restrict what options
# TODO: can be given to pkgsrc
# TODO: can be given to `nixpkgs.channels.${moduleName}.${name}`
decl =
cfg.${contextName} or cfg.default;
repos =
cfg
decl
|> mapAttrs (
name: args:
assert args ? source
|| abort ''
${./.}
`pkgsrc.${name} missing required attribute "source"`
${toString ./.}
`nixpkgs.channels.${contextName}.${name} missing required attribute "source"`
'';
args
|> flip removeAttrs ["source"]
((removeAttrs args ["source"])
// {inherit system;})
|> import args.source
|> lib.mkOverride 200
);
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"];
_module.args = removeAttrs repos ["pkgs"];
# nixpkgs =
# lib.mkIf (cfg ? pkgs)
# (let
# pkgs = cfg.pkgs;
# in
# lib.mkForce (
# (removeAttrs pkgs ["source"])
# // {
# flake.source = pkgs.source;
# }
# ));
nixpkgs =
if contextName == "hosts"
then {flake.source = lib.mkIf (decl ? pkgs) (lib.mkOverride 200 decl.pkgs.source);}
else {};
};
}

6
flake.lock generated
View file

@ -175,11 +175,11 @@
"systems": "systems_2"
},
"locked": {
"lastModified": 1770950436,
"narHash": "sha256-+h5jrsIJBea5P+rAk4OqUpScqnHYQTvCRUhgGv/MX34=",
"lastModified": 1770975056,
"narHash": "sha256-ZXTz/P3zUbbM6lNXzt91u8EwfNqhXpYMu8+wvFZqQHE=",
"owner": "cry128",
"repo": "nt",
"rev": "8725f5079f8f27b3faafeff90e5fc075d55e7d0a",
"rev": "f42dcdd49a7921a7f433512e83d5f93696632412",
"type": "github"
},
"original": {