private static function setupModules()
    {
        $aModuleLocations = [];

        //  Discover Nails modules
        $aModules = Components::modules();

        /**
         * Note: Key is full path, value is relative path from the application controllers
         * directory to where the modules are.
         */
        $aAbsolutePaths = [
            [rtrim(APPPATH, DIRECTORY_SEPARATOR), 'modules'],
            [rtrim(FCPATH, DIRECTORY_SEPARATOR), 'vendor', 'nails', 'common'],
        ];

        $aRelativePaths = [
            ['..', 'modules'],
            ['..', '..', 'vendor', 'nails', 'common'],
        ];

        array_walk(
            $aAbsolutePaths,
            function (&$aItem) {
                $aItem = implode(DIRECTORY_SEPARATOR, $aItem) . DIRECTORY_SEPARATOR;
            }
        );

        array_walk(
            $aRelativePaths,
            function (&$aItem) {
                $aItem = implode(DIRECTORY_SEPARATOR, $aItem) . DIRECTORY_SEPARATOR;
            }
        );

        $aModuleLocations = array_merge(
            $aModuleLocations,
            array_combine($aAbsolutePaths, $aRelativePaths)
        );

        //  Discovered Nails modules
        foreach ($aModules as $oModule) {
            $aModuleLocations[$oModule->path] = implode(
                    DIRECTORY_SEPARATOR,
                    ['..', '..', 'vendor', $oModule->name]
                ) . DIRECTORY_SEPARATOR;
        }

        // --------------------------------------------------------------------------

        /**
         * This hook happens before the config class loads (but the config file has
         * already been loaded). CI provides an interface to pass items to the config
         * file via the index.php file; we're going to leverage that here to set
         * the module locations.
         */

        //  Underscore casing is important
        global $assign_to_config;
        $key = 'modules_locations';

        if (empty($assign_to_config)) {
            $assign_to_config = [];
        }

        if (isset($assign_to_config[$key]) && is_array($assign_to_config[$key])) {

            //  Already set, merge the arrays
            $assign_to_config[$key] = array_merge($assign_to_config[$key], $aModuleLocations);

        } else {

            // Not set (or is set but not "proper", overwrite it as it's probably wrong anyway)
            $assign_to_config[$key] = $aModuleLocations;
        }
    }