# SPDX-FileCopyrightText: 2026 Qyriad # # SPDX-License-Identifier: EUPL-1.1 { name, lib, config, host, ... }: let inherit (lib.modules) mkIf ; inherit (lib.options) mkOption mkEnableOption literalExpression ; t = lib.types; inherit (import ./lib.nix { inherit lib; }) convenientAttrPath executablePathInStore recUpdateFoldl ; pkgs = host.pkgs; in { options = { enable = mkEnableOption "dynamicism for '${name}'"; source-options = mkOption { type = t.listOf convenientAttrPath; description = "A list of attrpaths of the NixOS option the dynamicism for '${name}' uses"; example = literalExpression '' [ [ "services" "gotosocial" "settings" ] "services.nginx.settings" ] ''; }; systemd-services-updated = mkOption { type = t.listOf t.str; description = '' A list of systemd unit names (including the suffix, e.g. `.service`) that need to be updated. ''; example = literalExpression '' [ "gotosocial.service" ] ''; default = lib.attrNames config.unitDropins; }; finalSettings = mkOption { type = t.attrsOf t.raw; internal = true; default = recUpdateFoldl (optPath: lib.setAttrByPath optPath (lib.getAttrFromPath optPath host.config) ) config.source-options; }; configFile = mkOption { type = t.nullOr t.pathInStore; internal = true; default = null; }; unitDropins = mkOption { type = t.attrsOf t.package; internal = true; }; activate = mkOption { type = executablePathInStore; internal = true; }; }; config = mkIf config.enable { activate = pkgs.writeShellApplication { name = "dynamicism-for-${name}-activate"; runtimeInputs = [ pkgs.systemd ]; text = let doEdits = config.unitDropins |> lib.mapAttrsToList (service: dropin: '' cat "${dropin}" | systemctl edit "${service}" --runtime --drop=dynix-${dropin.name} --stdin '') |> lib.concatStringsSep "\n"; doReloads = config.unitDropins |> lib.mapAttrsToList (service: _: '' systemctl reload-or-restart "${service}" '') |> lib.concatStringsSep "\n"; in '' ${doEdits} ${doReloads} ''; }; }; }