at 25.11-pre 1.3 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) 17 mkOption 18 mkEnableOption 19 types 20 doRename 21 ; 22in 23{ 24 options = { 25 services.foo.enable = mkEnableOption "foo"; 26 services.foos = mkOption { 27 type = types.attrsOf ( 28 types.submodule { 29 options = { 30 bar = mkOption { type = types.str; }; 31 }; 32 } 33 ); 34 default = { }; 35 }; 36 result = mkOption { }; 37 }; 38 imports = [ 39 (doRename { 40 from = [ 41 "services" 42 "foo" 43 "bar" 44 ]; 45 to = [ 46 "services" 47 "foos" 48 "" 49 "bar" 50 ]; 51 visible = true; 52 warn = false; 53 use = x: x; 54 withPriority = true; 55 condition = config.services.foo.enable; 56 }) 57 ]; 58}