mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
rename.nix: Don't use splitString
It's very slow.
This commit is contained in:
parent
8f4c5b05d5
commit
b218c02a3c
1 changed files with 57 additions and 58 deletions
|
@ -4,28 +4,29 @@ with pkgs.lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
alias = from: to: {
|
alias = from: to: rename {
|
||||||
|
inherit from to;
|
||||||
name = "Alias";
|
name = "Alias";
|
||||||
msg.use = x: x;
|
use = id;
|
||||||
msg.define = x: x;
|
define = id;
|
||||||
};
|
};
|
||||||
|
|
||||||
obsolete = from: to: {
|
obsolete = from: to: rename {
|
||||||
|
inherit from to;
|
||||||
name = "Obsolete name";
|
name = "Obsolete name";
|
||||||
msg.use = x:
|
use = x: builtins.trace "Obsolete option ${showOption from} is used instead of ${showOption to}." x;
|
||||||
builtins.trace "Obsolete option `${from}' is used instead of `${to}'." x;
|
define = x: builtins.trace "Obsolete option ${showOption from} is defined instead of ${showOption to}." x;
|
||||||
msg.define = x:
|
|
||||||
builtins.trace "Obsolete option `${from}' is defined instead of `${to}'." x;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
deprecated = from: to: {
|
deprecated = from: to: rename {
|
||||||
|
inherit from to;
|
||||||
name = "Deprecated name";
|
name = "Deprecated name";
|
||||||
msg.use = x:
|
use = x: abort "Deprecated option ${showOption from} is used instead of ${showOption to}.";
|
||||||
abort "Deprecated option `${from}' is used instead of `${to}'.";
|
define = x: abort "Deprecated option ${showOption from} is defined instead of ${showOption to}.";
|
||||||
msg.define = x:
|
|
||||||
abort "Deprecated option `${from}' is defined instead of `${to}'.";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
showOption = name: "`${concatStringsSep "." name}'";
|
||||||
|
|
||||||
zipModules = list:
|
zipModules = list:
|
||||||
zipAttrsWith (n: v:
|
zipAttrsWith (n: v:
|
||||||
if tail v != [] then
|
if tail v != [] then
|
||||||
|
@ -38,19 +39,17 @@ let
|
||||||
else head v
|
else head v
|
||||||
) list;
|
) list;
|
||||||
|
|
||||||
rename = statusTemplate: from: to:
|
rename = { from, to, name, use, define }:
|
||||||
let
|
let
|
||||||
status = statusTemplate from to;
|
setTo = setAttrByPath to;
|
||||||
setTo = setAttrByPath (splitString "." to);
|
setFrom = setAttrByPath from;
|
||||||
setFrom = setAttrByPath (splitString "." from);
|
toOf = attrByPath to
|
||||||
toOf = attrByPath (splitString "." to)
|
(abort "Renaming error: option ${showOption to} does not exists.");
|
||||||
(abort "Renaming error: option `${to}' does not exists.");
|
fromOf = attrByPath from
|
||||||
fromOf = attrByPath (splitString "." from)
|
(abort "Internal error: option ${showOption from} should be declared.");
|
||||||
(abort "Internal error: option `${from}' should be declared.");
|
|
||||||
in
|
in
|
||||||
[ { options = setFrom (mkOption {
|
[ { options = setFrom (mkOption {
|
||||||
description = "${status.name} of <option>${to}</option>.";
|
apply = x: use (toOf config);
|
||||||
apply = x: status.msg.use (toOf config);
|
|
||||||
visible = false;
|
visible = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -58,68 +57,68 @@ let
|
||||||
extraConfigs =
|
extraConfigs =
|
||||||
let externalDefs = (fromOf options).definitions; in
|
let externalDefs = (fromOf options).definitions; in
|
||||||
if externalDefs == [] then []
|
if externalDefs == [] then []
|
||||||
else map (def: def.value) (status.msg.define externalDefs);
|
else map (def: def.value) (define externalDefs);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
obsolete' = option: let option' = splitString "." option; in singleton
|
obsolete' = option: singleton
|
||||||
{ options = setAttrByPath option' (mkOption {
|
{ options = setAttrByPath option (mkOption {
|
||||||
default = null;
|
default = null;
|
||||||
visible = false;
|
visible = false;
|
||||||
});
|
});
|
||||||
config.warnings = optional (getAttrFromPath option' config != null)
|
config.warnings = optional (getAttrFromPath option config != null)
|
||||||
"The option `${option}' set in your configuration no longer has any effect; please remove it.";
|
"The option ${showOption option} defined in your configuration no longer has any effect; please remove it.";
|
||||||
};
|
};
|
||||||
|
|
||||||
in zipModules ([]
|
in zipModules ([]
|
||||||
|
|
||||||
# usage example:
|
# usage example:
|
||||||
# ++ rename alias "services.xserver.slim.theme" "services.xserver.displayManager.slim.theme"
|
# ++ alias [ "services" "xserver" "slim" "theme" ] [ "services" "xserver" "displayManager" "slim" "theme" ]
|
||||||
++ rename obsolete "environment.extraPackages" "environment.systemPackages"
|
++ obsolete [ "environment" "extraPackages" ] [ "environment" "systemPackages" ]
|
||||||
++ rename obsolete "environment.enableBashCompletion" "programs.bash.enableCompletion"
|
++ obsolete [ "environment" "enableBashCompletion" ] [ "programs" "bash" "enableCompletion" ]
|
||||||
|
|
||||||
++ rename obsolete "security.extraSetuidPrograms" "security.setuidPrograms"
|
++ obsolete [ "security" "extraSetuidPrograms" ] [ "security" "setuidPrograms" ]
|
||||||
++ rename obsolete "networking.enableWLAN" "networking.wireless.enable"
|
++ obsolete [ "networking" "enableWLAN" ] [ "networking" "wireless" "enable" ]
|
||||||
++ rename obsolete "networking.enableRT73Firmware" "networking.enableRalinkFirmware"
|
++ obsolete [ "networking" "enableRT73Firmware" ] [ "networking" "enableRalinkFirmware" ]
|
||||||
|
|
||||||
# FIXME: Remove these eventually.
|
# FIXME: Remove these eventually.
|
||||||
++ rename obsolete "boot.systemd.sockets" "systemd.sockets"
|
++ obsolete [ "boot" "systemd" "sockets" ] [ "systemd" "sockets" ]
|
||||||
++ rename obsolete "boot.systemd.targets" "systemd.targets"
|
++ obsolete [ "boot" "systemd" "targets" ] [ "systemd" "targets" ]
|
||||||
++ rename obsolete "boot.systemd.services" "systemd.services"
|
++ obsolete [ "boot" "systemd" "services" ] [ "systemd" "services" ]
|
||||||
|
|
||||||
# Old Grub-related options.
|
# Old Grub-related options.
|
||||||
++ rename obsolete "boot.copyKernels" "boot.loader.grub.copyKernels"
|
++ obsolete [ "boot" "copyKernels" ] [ "boot" "loader" "grub" "copyKernels" ]
|
||||||
++ rename obsolete "boot.extraGrubEntries" "boot.loader.grub.extraEntries"
|
++ obsolete [ "boot" "extraGrubEntries" ] [ "boot" "loader" "grub" "extraEntries" ]
|
||||||
++ rename obsolete "boot.extraGrubEntriesBeforeNixos" "boot.loader.grub.extraEntriesBeforeNixOS"
|
++ obsolete [ "boot" "extraGrubEntriesBeforeNixos" ] [ "boot" "loader" "grub" "extraEntriesBeforeNixOS" ]
|
||||||
++ rename obsolete "boot.grubDevice" "boot.loader.grub.device"
|
++ obsolete [ "boot" "grubDevice" ] [ "boot" "loader" "grub" "device" ]
|
||||||
++ rename obsolete "boot.bootMount" "boot.loader.grub.bootDevice"
|
++ obsolete [ "boot" "bootMount" ] [ "boot" "loader" "grub" "bootDevice" ]
|
||||||
++ rename obsolete "boot.grubSplashImage" "boot.loader.grub.splashImage"
|
++ obsolete [ "boot" "grubSplashImage" ] [ "boot" "loader" "grub" "splashImage" ]
|
||||||
|
|
||||||
++ rename obsolete "boot.initrd.extraKernelModules" "boot.initrd.kernelModules"
|
++ obsolete [ "boot" "initrd" "extraKernelModules" ] [ "boot" "initrd" "kernelModules" ]
|
||||||
|
|
||||||
# OpenSSH
|
# OpenSSH
|
||||||
++ rename obsolete "services.sshd.ports" "services.openssh.ports"
|
++ obsolete [ "services" "sshd" "ports" ] [ "services" "openssh" "ports" ]
|
||||||
++ rename alias "services.sshd.enable" "services.openssh.enable"
|
++ alias [ "services" "sshd" "enable" ] [ "services" "openssh" "enable" ]
|
||||||
++ rename obsolete "services.sshd.allowSFTP" "services.openssh.allowSFTP"
|
++ obsolete [ "services" "sshd" "allowSFTP" ] [ "services" "openssh" "allowSFTP" ]
|
||||||
++ rename obsolete "services.sshd.forwardX11" "services.openssh.forwardX11"
|
++ obsolete [ "services" "sshd" "forwardX11" ] [ "services" "openssh" "forwardX11" ]
|
||||||
++ rename obsolete "services.sshd.gatewayPorts" "services.openssh.gatewayPorts"
|
++ obsolete [ "services" "sshd" "gatewayPorts" ] [ "services" "openssh" "gatewayPorts" ]
|
||||||
++ rename obsolete "services.sshd.permitRootLogin" "services.openssh.permitRootLogin"
|
++ obsolete [ "services" "sshd" "permitRootLogin" ] [ "services" "openssh" "permitRootLogin" ]
|
||||||
++ rename obsolete "services.xserver.startSSHAgent" "services.xserver.startOpenSSHAgent"
|
++ obsolete [ "services" "xserver" "startSSHAgent" ] [ "services" "xserver" "startOpenSSHAgent" ]
|
||||||
|
|
||||||
# KDE
|
# KDE
|
||||||
++ rename deprecated "kde.extraPackages" "environment.kdePackages"
|
++ deprecated [ "kde" "extraPackages" ] [ "environment" "kdePackages" ]
|
||||||
# ++ rename obsolete "environment.kdePackages" "environment.systemPackages" # !!! doesn't work!
|
# ++ obsolete [ "environment" "kdePackages" ] [ "environment" "systemPackages" ] # !!! doesn't work!
|
||||||
|
|
||||||
# Multiple efi bootloaders now
|
# Multiple efi bootloaders now
|
||||||
++ rename obsolete "boot.loader.efi.efibootmgr.enable" "boot.loader.efi.canTouchEfiVariables"
|
++ obsolete [ "boot" "loader" "efi" "efibootmgr" "enable" ] [ "boot" "loader" "efi" "canTouchEfiVariables" ]
|
||||||
|
|
||||||
# NixOS environment changes
|
# NixOS environment changes
|
||||||
# !!! this hardcodes bash, could we detect from config which shell is actually used?
|
# !!! this hardcodes bash, could we detect from config which shell is actually used?
|
||||||
++ rename obsolete "environment.promptInit" "programs.bash.promptInit"
|
++ obsolete [ "environment" "promptInit" ] [ "programs" "bash" "promptInit" ]
|
||||||
|
|
||||||
# Options that are obsolete and have no replacement.
|
# Options that are obsolete and have no replacement.
|
||||||
++ obsolete' "boot.loader.grub.bootDevice"
|
++ obsolete' [ "boot" "loader" "grub" "bootDevice" ]
|
||||||
++ obsolete' "boot.initrd.luks.enable"
|
++ obsolete' [ "boot" "initrd" "luks" "enable" ]
|
||||||
|
|
||||||
) # do not add renaming after this.
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue