at 24.11-pre 1.2 kB view raw
1/** 2 Simulate a migration from a single-instance `services.foo` to a multi instance 3 `services.foos.<name>` module, where `name = ""` serves as the legacy / 4 compatibility instance. 5 6 - No instances must exist, unless one is defined in the multi-instance module, 7 or if the legacy enable option is set to true. 8 - The legacy instance options must be renamed to the new instance, if it exists. 9 10 The relevant scenarios are tested in separate files: 11 - ./doRename-condition-enable.nix 12 - ./doRename-condition-no-enable.nix 13*/ 14{ config, lib, ... }: 15let 16 inherit (lib) mkOption mkEnableOption types doRename; 17in 18{ 19 options = { 20 services.foo.enable = mkEnableOption "foo"; 21 services.foos = mkOption { 22 type = types.attrsOf (types.submodule { 23 options = { 24 bar = mkOption { type = types.str; }; 25 }; 26 }); 27 default = { }; 28 }; 29 result = mkOption {}; 30 }; 31 imports = [ 32 (doRename { 33 from = [ "services" "foo" "bar" ]; 34 to = [ "services" "foos" "" "bar" ]; 35 visible = true; 36 warn = false; 37 use = x: x; 38 withPriority = true; 39 condition = config.services.foo.enable; 40 }) 41 ]; 42}