diff --git a/modules/module-list.nix b/modules/module-list.nix index 39b1bb325b64..e644a9bb77d6 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -27,6 +27,7 @@ ./programs/pwdutils/pwdutils.nix ./programs/ssh.nix ./programs/ssmtp.nix + ./rename.nix ./security/consolekit.nix ./security/pam.nix ./security/policykit.nix diff --git a/modules/rename.nix b/modules/rename.nix new file mode 100644 index 000000000000..777b95cc9775 --- /dev/null +++ b/modules/rename.nix @@ -0,0 +1,41 @@ +{pkgs, options, config, ...}: + + +let + to = throw "This is just a dummy keyword"; + alias = { name = "Alias"; }; + obsolete = { name = "Obsolete name"; }; + + zipModules = list: with pkgs.lib; + zip (n: v: + if tail v != [] then zipModules v else head v + ) list; + + rename = fromStatus: from: keyword: to: with pkgs.lib; + let + setTo = setAttrByPath (splitString "." to); + setFrom = setAttrByPath (splitString "." from); + toOf = attrByPath (splitString "." to) (abort "bad renaming"); + fromOf = attrByPath (splitString "." from) (abort "IE: renaming error"); + in + [{ + options = setFrom (mkOption { + description = "${fromStatus.name} of ."; + apply = x: toOf config; + }); + }] ++ + [{ + options = setTo (mkOption { + extraConfigs = map (def: def.value) (fromOf options).definitions; + }); + }]; + +in zipModules ([] + +# usage example: +# ++ rename alias "services.xserver.slim.theme" to "services.xserver.displayManager.slim.theme" +# ++ rename obsolete "environment.extraPackages" to "environment.systemPackages" + + + +) # do not add renaming after this.