pass sources via specialArgs (#464)

this gets rid of ugly in-place imports and upward paths

Reviewed-on: Fediversity/Fediversity#464
Reviewed-by: kiara Grouwstra <kiara@procolix.eu>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Co-committed-by: Valentin Gagarin <valentin.gagarin@tweag.io>
This commit is contained in:
Valentin Gagarin 2025-07-16 10:53:36 +02:00 committed by kiara Grouwstra
parent f2017aaeb4
commit b791bd515d
4 changed files with 36 additions and 28 deletions

View file

@ -1,15 +1,4 @@
let { sources, ... }:
# pulling this in manually over from module args resolves an infinite recursion.
# FIXME: instead untangle `//infra/flake-part.nix` and make it stop passing wild functions.
# move moving towards a portable-services-like pattern where some things are submodules.
# Right now those wild functions are for parameterising a bunch of things,
# and the modular way to do that would be options --
# obviously you can't use those for `imports`,
# so one way to decouple fixpoints is to isolate them into submodules.
# Therefore one approach would be to try to go down the call graph,
# and see where what's currently a function could be a `submodule` field of something else.
sources = import ../../npins;
in
{ {
_class = "nixos"; _class = "nixos";

View file

@ -27,7 +27,6 @@ let
_module.args = { _module.args = {
inherit inherit
inputs inputs
sources
keys keys
secrets secrets
; ;
@ -37,6 +36,10 @@ let
./common/proxmox-qemu-vm.nix ./common/proxmox-qemu-vm.nix
]; ];
nixos.specialArgs = {
inherit sources;
};
imports = imports =
[ [
./common/resource.nix ./common/resource.nix
@ -66,17 +69,33 @@ let
vmNames: vmNames:
{ providers, ... }: { providers, ... }:
{ {
providers.local = inputs.nixops4.modules.nixops4Provider.local; # XXX: this type merge is for adding `specialArgs` to resource modules
resources = genAttrs vmNames (vmName: { options.resources = mkOption {
type = providers.local.exec; type =
imports = [ with lib.types;
inputs.nixops4-nixos.modules.nixops4Resource.nixos lazyAttrsOf (submoduleWith {
(makeResourceModule { class = "nixops4Resource";
inherit vmName; modules = [ ];
isTestVm = false; # TODO(@fricklerhandwerk): we may want to pass through all of `specialArgs`
}) # once we're sure it's sane. leaving it here for better control during refactoring.
]; specialArgs = {
}); inherit sources;
};
});
};
config = {
providers.local = inputs.nixops4.modules.nixops4Provider.local;
resources = genAttrs vmNames (vmName: {
type = providers.local.exec;
imports = [
inputs.nixops4-nixos.modules.nixops4Resource.nixos
(makeResourceModule {
inherit vmName;
isTestVm = false;
})
];
});
};
}; };
makeDeployment' = vmName: makeDeployment [ vmName ]; makeDeployment' = vmName: makeDeployment [ vmName ];

View file

@ -1,17 +1,17 @@
{ {
config, config,
sources,
... ...
}: }:
let let
name = "panel"; name = "panel";
sources = import ../../../npins;
in in
{ {
_class = "nixos"; _class = "nixos";
imports = [ imports = [
(import ../../../panel { }).module (../../../panel { }).module
(import "${sources.home-manager}/nixos") "${sources.home-manager}/nixos"
]; ];
security.acme = { security.acme = {

View file

@ -45,7 +45,7 @@ in
''; '';
}; };
module = import ./nix/configuration.nix; module = ./nix/configuration.nix;
tests = pkgs.callPackage ./nix/tests.nix { }; tests = pkgs.callPackage ./nix/tests.nix { };
# re-export inputs so they can be overridden granularly # re-export inputs so they can be overridden granularly