From b791bd515d520020ae1560ed403893d36d360031 Mon Sep 17 00:00:00 2001 From: Valentin Gagarin Date: Wed, 16 Jul 2025 10:53:36 +0200 Subject: [PATCH] pass `sources` via `specialArgs` (#464) this gets rid of ugly in-place imports and upward paths Reviewed-on: https://git.fediversity.eu/Fediversity/Fediversity/pulls/464 Reviewed-by: kiara Grouwstra Co-authored-by: Valentin Gagarin Co-committed-by: Valentin Gagarin --- infra/common/proxmox-qemu-vm.nix | 13 +-------- infra/flake-part.nix | 43 +++++++++++++++++++++--------- machines/dev/fedi201/fedipanel.nix | 6 ++--- panel/default.nix | 2 +- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/infra/common/proxmox-qemu-vm.nix b/infra/common/proxmox-qemu-vm.nix index 961bb963..9176d0eb 100644 --- a/infra/common/proxmox-qemu-vm.nix +++ b/infra/common/proxmox-qemu-vm.nix @@ -1,15 +1,4 @@ -let - # 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 +{ sources, ... }: { _class = "nixos"; diff --git a/infra/flake-part.nix b/infra/flake-part.nix index 4ad559bc..e970d190 100644 --- a/infra/flake-part.nix +++ b/infra/flake-part.nix @@ -27,7 +27,6 @@ let _module.args = { inherit inputs - sources keys secrets ; @@ -37,6 +36,10 @@ let ./common/proxmox-qemu-vm.nix ]; + nixos.specialArgs = { + inherit sources; + }; + imports = [ ./common/resource.nix @@ -66,17 +69,33 @@ let vmNames: { providers, ... }: { - 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; - }) - ]; - }); + # XXX: this type merge is for adding `specialArgs` to resource modules + options.resources = mkOption { + type = + with lib.types; + lazyAttrsOf (submoduleWith { + class = "nixops4Resource"; + modules = [ ]; + # 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 ]; diff --git a/machines/dev/fedi201/fedipanel.nix b/machines/dev/fedi201/fedipanel.nix index d630b821..ba87bf4b 100644 --- a/machines/dev/fedi201/fedipanel.nix +++ b/machines/dev/fedi201/fedipanel.nix @@ -1,17 +1,17 @@ { config, + sources, ... }: let name = "panel"; - sources = import ../../../npins; in { _class = "nixos"; imports = [ - (import ../../../panel { }).module - (import "${sources.home-manager}/nixos") + (../../../panel { }).module + "${sources.home-manager}/nixos" ]; security.acme = { diff --git a/panel/default.nix b/panel/default.nix index 74865386..a8f716c9 100644 --- a/panel/default.nix +++ b/panel/default.nix @@ -45,7 +45,7 @@ in ''; }; - module = import ./nix/configuration.nix; + module = ./nix/configuration.nix; tests = pkgs.callPackage ./nix/tests.nix { }; # re-export inputs so they can be overridden granularly